RecursionError when trying to print headers

346 views
Skip to first unread message

Gabriele Russo Russo

unread,
Dec 4, 2019, 10:36:49 AM12/4/19
to Pika
Hello,
I am trying to access the "timestamp_in_ms" header provided by rabbitmq_message_timestamp plugin. When I try to print the content of the `headers` field of the BasicProperties object, I get the following error:

[...]
    print(repr(properties.headers["timestamp_in_ms"]))
  File "/usr/lib/python3.8/site-packages/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  File "/usr/lib/python3.8/site-packages/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  File "/usr/lib/python3.8/site-packages/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  [Previous line repeated 328 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object


I am using the latest Pika package available on Arch Linux (1.0.0-1). Is this a Pika bug?

Luke Bakken

unread,
Dec 5, 2019, 10:28:46 AM12/5/19
to Pika
Hi Gabriele,

Please provide a complete example I can run to observe this behavior, with instructions on how to run it. I can guess how to reproduce this, but if you'd like it resolved quickly, providing code I can run is the fastest way.

Thanks,
Luke

Gabriele Russo Russo

unread,
Dec 5, 2019, 11:49:32 AM12/5/19
to Pika
Hi Luke,
these are the steps required to reproduce the issue:
1) Write a simple consumer using the example code provided here: https://pika.readthedocs.io/en/stable/examples/blocking_basic_get.html
2) Enable the rabbitmq_message_timestamp plugin
3) Publish a message
4) Run the consumer.

(Actually, I guess step 2 could be replaced by "Publish a message with a header which is a number".)

Luke Bakken

unread,
Dec 10, 2019, 10:14:35 AM12/10/19
to Pika
Thanks for your patience, I'm checking this out now.

Luke Bakken

unread,
Dec 10, 2019, 11:02:38 AM12/10/19
to Pika
Hi,

I can't reproduce this issue. I used the following code after publishing a message to the test queue with a timestamp_in_ms header using numeric value 12345678901234567890 in one test and 1234567890 in another

import pika

connection = pika.BlockingConnection()
channel = connection.channel()
method_frame, header_frame, body = channel.basic_get('test')
if method_frame:
    print(method_frame, header_frame, body)
    print(repr(header_frame.headers["timestamp_in_ms"]))
    channel.basic_ack(method_frame.delivery_tag)
else:
    print('No message returned')

Output:

(venv) lbakken@MESSIAEN ~/issues/pika/print-headers-infinite-recursion
$ python ./repro.py
<Basic.GetOk(['delivery_tag=1', 'exchange=', 'message_count=0', 'redelivered=False', 'routing_key=test'])> <BasicProperties(['delivery_mode=1', "headers={'timestamp_in_ms': 12345678901234567000L}"])> b'MSG THREE'
12345678901234567000L
(venv) lbakken@MESSIAEN ~/issues/pika/print-headers-infinite-recursion

$ python --version
Python 3.7.5

(venv) lbakken@MESSIAEN ~/issues/pika/print-headers-infinite-recursion
$ pip list
Package    Version Location
---------- ------- ------------------------------------
pika       1.1.0   /Users/lbakken/development/pika/pika
pip        19.3.1
setuptools 42.0.2
wheel      0.33.6

I'm using RabbitMQ 3.8.2. Everything is on my local OS X laptop.

I even added some tests that show this appears to work 


Thanks,
Luke

Gabriele Russo Russo

unread,
Dec 10, 2019, 12:28:52 PM12/10/19
to Pika
Thanks for spending some time checking the issue. The root of the error is probably somewhere else on my system (Python version/RabbitMQ, i don't know). It is not a blocking issue for me anyway.

Thanks again.

Luke Bakken

unread,
Dec 10, 2019, 12:30:37 PM12/10/19
to Pika
No problem. I doubt it's a RabbitMQ issue. When I have time to install Python 3.8 I'll give that a try. I haven't tried in a Linux environment yet, either.

Luke Bakken

unread,
Dec 10, 2019, 12:53:26 PM12/10/19
to Pika
Hi Gabriele,

I installed Python 3.8.0 (after resolving this issue https://github.com/pyenv/pyenv/issues/1011).

Guess what, this error is specific to that Python version:

$ python -munittest tests/unit/spec_tests.py
.E
======================================================================
ERROR: test_headers_repr (tests.unit.spec_tests.BasicPropertiesTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/lbakken/development/pika/pika/tests/unit/spec_tests.py", line 34, in test_headers_repr
    self.assertEqual(repr(p.headers[hdr]), '912598613L')
  File "/Users/lbakken/development/pika/pika/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  File "/Users/lbakken/development/pika/pika/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  File "/Users/lbakken/development/pika/pika/pika/compat.py", line 122, in __repr__
    return str(self) + 'L'
  [Previous line repeated 323 more times]
RecursionError: maximum recursion depth exceeded while calling a Python object

----------------------------------------------------------------------
Ran 2 tests in 0.002s

FAILED (errors=1)

I will continue to investigate

Luke Bakken

unread,
Dec 10, 2019, 1:19:26 PM12/10/19
to Pika
If you have a second to review, and ideally test in your environment, that would be appreciated:

Gabriele Russo Russo

unread,
Dec 11, 2019, 2:23:49 AM12/11/19
to Pika
That fixes the issue in my environment too. Thank you very much.
Reply all
Reply to author
Forward
0 new messages