Bug 2295380 - pylibmc.Client fails to init: TypeError: 'NoneType' object is not subscriptable
Summary: pylibmc.Client fails to init: TypeError: 'NoneType' object is not subscriptable
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pylibmc
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: František Zatloukal
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.13 2251780
TreeView+ depends on / blocked
 
Reported: 2024-07-03 10:35 UTC by Miro Hrončok
Modified: 2024-07-03 12:11 UTC (History)
6 users (show)

Fixed In Version: python-pylibmc-1.6.3-9.fc41
Clone Of:
Environment:
Last Closed: 2024-07-03 12:11:27 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github lericson pylibmc pull 292 0 None open Stop accessing None as a dictionary 2024-07-03 11:02:20 UTC

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.


Note You need to log in before you can comment on or make changes to this bug.