Skip to content

Fix potential AttributeError on 'stamps'#8115

Merged
auvipy merged 1 commit intocelery:mainfrom
Darkheir:fix/stamps_attribute_error
Mar 8, 2023
Merged

Fix potential AttributeError on 'stamps'#8115
auvipy merged 1 commit intocelery:mainfrom
Darkheir:fix/stamps_attribute_error

Conversation

@Darkheir
Copy link
Copy Markdown
Contributor

@Darkheir Darkheir commented Mar 8, 2023

Description

The current check will fail if the attribute doesn't exists on the request instance.

Stack trace of the error:

AttributeError: 'Bunch' object has no attribute 'stamps'
  File "celery/worker/worker.py", line 202, in start
    self.blueprint.start(self)
  File "celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "celery/bootsteps.py", line 365, in start
    return self.obj.start()
  File "celery/worker/consumer/consumer.py", line 336, in start
    blueprint.start(self)
  File "celery/bootsteps.py", line 116, in start
    step.start(parent)
  File "celery/worker/consumer/consumer.py", line 726, in start
    c.loop(*c.loop_args())
  File "celery/worker/loops.py", line 130, in synloop
    connection.drain_events(timeout=2.0)
  File "kombu/connection.py", line 331, in drain_events
    return self.transport.drain_events(self.connection, **kwargs)
  File "kombu/transport/virtual/base.py", line 983, in drain_events
    get(self._deliver, timeout=timeout)
  File "kombu/transport/redis.py", line 588, in get
    ret = self.handle_event(fileno, event)
  File "kombu/transport/redis.py", line 570, in handle_event
    return self.on_readable(fileno), self
  File "kombu/transport/redis.py", line 566, in on_readable
    chan.handlers[type]()
  File "kombu/transport/redis.py", line 971, in _brpop_read
    self.connection._deliver(loads(bytes_to_str(item)), dest)
  File "kombu/transport/virtual/base.py", line 1003, in _deliver
    callback(message)
  File "kombu/transport/virtual/base.py", line 630, in _callback
    return callback(message)
  File "kombu/messaging.py", line 642, in _receive_callback
    return on_m(message) if on_m else self.receive(decoded, message)
  File "celery/worker/consumer/consumer.py", line 644, in on_task_received
    return on_unknown_task(None, message, exc)
  File "celery/worker/consumer/consumer.py", line 591, in on_unknown_task
    self.app.backend.mark_as_failure(
  File "celery/backends/base.py", line 167, in mark_as_failure
    self.store_result(task_id, exc, state,
  File "celery/backends/base.py", line 526, in store_result
    self._store_result(task_id, result, state, traceback,
  File "celery/backends/base.py", line 963, in _store_result
    meta = self._get_result_meta(result=result, state=state,
  File "celery/backends/base.py", line 494, in _get_result_meta
    if getattr(request, 'stamps'):

request.delivery_info else None,
}
if getattr(request, 'stamps'):
if getattr(request, 'stamps', None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you mind adding a unit test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :-)

@auvipy auvipy added this to the 5.3 milestone Mar 8, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 8, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change

Comparison is base (32a83e2) 87.02% compared to head (19716d7) 87.02%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8115   +/-   ##
=======================================
  Coverage   87.02%   87.02%           
=======================================
  Files         148      148           
  Lines       18445    18445           
  Branches     2515     2515           
=======================================
  Hits        16051    16051           
  Misses       2116     2116           
  Partials      278      278           
Flag Coverage Δ
unittests 86.99% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
celery/backends/base.py 93.03% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Darkheir Darkheir force-pushed the fix/stamps_attribute_error branch from 2527170 to 19716d7 Compare March 8, 2023 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants