Bug 2295380

Summary: pylibmc.Client fails to init: TypeError: 'NoneType' object is not subscriptable
Product: [Fedora] Fedora Reporter: Miro Hrončok <mhroncok>
Component: python-pylibmcAssignee: František Zatloukal <fzatlouk>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: rawhideCC: aurelien, epel-packagers-sig, fzatlouk, metherid, michel, pj.pandit
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: python-pylibmc-1.6.3-9.fc41 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-07-03 12:11:27 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2244836, 2251780    

Description Miro Hrončok 2024-07-03 10:35:42 UTC
>>> import pylibmc
>>> m = pylibmc.Client(["10.0.0.1"], binary=True)
Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
Traceback (most recent call last):
  File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
    super().__init__(servers=translate_server_specs(servers),
TypeError: 'NoneType' object is not subscriptable
...
Exception ignored in PyMapping_HasKeyString(); consider using PyMapping_HasKeyStringWithError(), PyMapping_GetOptionalItemString() or PyMapping_GetItemString():
Traceback (most recent call last):
  File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
    super().__init__(servers=translate_server_specs(servers),
TypeError: 'NoneType' object is not subscriptable


python3-pylibmc-1.6.3-7.fc41.x86_64
python3-3.13.0~b3-1.fc41.x86_64

Comment 1 Miro Hrončok 2024-07-03 10:57:47 UTC
Replacing PyMapping_HasKeyString with PyMapping_HasKeyStringWithError results in:

>>> import pylibmc
>>> m = pylibmc.Client(["10.0.0.1"], binary=True)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    m = pylibmc.Client(["10.0.0.1"], binary=True)
  File "/usr/lib64/python3.13/site-packages/pylibmc/client.py", line 142, in __init__
    super().__init__(servers=translate_server_specs(servers),
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     binary=binary,
                     ^^^^^^^^^^^^^^
                     username=username, password=password,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                     behaviors=_behaviors_numeric(behaviors))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

-------------


My assumption is this:

>>> pylibmc.client._behaviors_numeric(None) is None
True

When behaviors is None (the default), it passes None to _pylibmc.client behaviors.

Without it, it works:

>>> _pylibmc.client(servers=pylibmc.client.translate_server_specs(["10.0.0.1"]))
<client object at 0x7f0874a59970>

But setting it to None fails:

>>> _pylibmc.client(servers=pylibmc.client.translate_server_specs(["10.0.0.1"]), behaviors=None)
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
    _pylibmc.client(servers=pylibmc.client.translate_server_specs(["10.0.0.1"]), behaviors=None)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable


Previously, the error resulted in treating the result as if the key was not in the dict.

Hence, this should fix this:



diff --git a/src/_pylibmcmodule.c b/src/_pylibmcmodule.c
index a34d2b5..545b658 100644
--- a/src/_pylibmcmodule.c
+++ b/src/_pylibmcmodule.c
@@ -2082,7 +2082,7 @@ static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *self,
     char *key;
 
     for (b = PylibMC_behaviors; b->name != NULL; b++) {
-        if (!PyMapping_HasKeyString(behaviors, b->name)) {
+        if (behaviors == Py_None || !PyMapping_HasKeyString(behaviors, b->name)) {
             continue;
         } else if ((py_v = PyMapping_GetItemString(behaviors, b->name)) == NULL) {
             goto error;
@@ -2112,7 +2112,7 @@ static PyObject *PylibMC_Client_set_behaviors(PylibMC_Client *self,
     }
 
     for (b = PylibMC_callbacks; b->name != NULL; b++) {
-        if (!PyMapping_HasKeyString(behaviors, b->name)) {
+        if (behaviors == Py_None || !PyMapping_HasKeyString(behaviors, b->name)) {
             continue;
         } else if ((py_v = PyMapping_GetItemString(behaviors, b->name)) == NULL) {
             goto error;


Indeed:


>>> import pylibmc
>>> m = pylibmc.Client(["10.0.0.1"], binary=True)
>>>

Comment 2 Miro Hrončok 2024-07-03 11:02:21 UTC
I belive this should fix it: https://github.com/lericson/pylibmc/pull/292

Comment 3 Fedora Update System 2024-07-03 12:06:57 UTC
FEDORA-2024-9ec2b42d96 (python-pylibmc-1.6.3-9.fc41) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-9ec2b42d96

Comment 4 Fedora Update System 2024-07-03 12:11:27 UTC
FEDORA-2024-9ec2b42d96 (python-pylibmc-1.6.3-9.fc41) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.