Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(beat): debug statement should only log AsyncResult.id if it exists #8428

Merged
merged 1 commit into from Aug 8, 2023
Merged

Conversation

bmrobin
Copy link
Contributor

@bmrobin bmrobin commented Aug 8, 2023

Description

celery.beat.apply_entry() assumes that apply_async() will return an AsyncResult containing an ID. this is not always the case: for example when Django's transaction.on_commit() wraps the invoked task. this proposed fix simply modifies the debug() logging statement to more safely handle the result that is being logged after the task is created.

Fixes #8372

@Nusnus
Copy link
Member

Nusnus commented Aug 8, 2023

==================================== ERRORS ====================================
  ___________________ ERROR collecting t/unit/app/test_beat.py ___________________
  .tox/3.8-unit/lib/python3.8/site-packages/_pytest/python.py:617: in _importtestmodule
      mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
  .tox/3.8-unit/lib/python3.8/site-packages/_pytest/pathlib.py:565: in import_path
      importlib.import_module(module_name)
  /opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/importlib/__init__.py:127: in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
  <frozen importlib._bootstrap>:1014: in _gcd_import
      ???
  <frozen importlib._bootstrap>:991: in _find_and_load
      ???
  <frozen importlib._bootstrap>:975: in _find_and_load_unlocked
      ???
  <frozen importlib._bootstrap>:671: in _load_unlocked
      ???
  .tox/3.8-unit/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:169: in exec_module
      source_stat, co = _rewrite_test(fn, self.config)
  .tox/3.8-unit/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:351: in _rewrite_test
      tree = ast.parse(source, filename=strfn)
  /opt/hostedtoolcache/Python/3.8.17/x64/lib/python3.8/ast.py:47: in parse
      return compile(source, filename, mode, flags,
  E     File "/home/runner/work/celery/celery/t/unit/app/test_beat.py", line 307
  E       with (patch.object(s, 'apply_async') as mock_apply_async,
  E                                            ^
  E   SyntaxError: invalid syntax

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (ef50442) 87.42% compared to head (865ccc9) 87.42%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8428   +/-   ##
=======================================
  Coverage   87.42%   87.42%           
=======================================
  Files         148      148           
  Lines       18477    18479    +2     
  Branches     3153     3154    +1     
=======================================
+ Hits        16153    16155    +2     
  Misses       2034     2034           
  Partials      290      290           
Flag Coverage Δ
unittests 87.39% <100.00%> (+<0.01%) ⬆️

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

Files Changed Coverage Δ
celery/beat.py 91.58% <100.00%> (+0.04%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Nusnus
Copy link
Member

Nusnus commented Aug 8, 2023

Seems to be an issue with Python 3.8 not supporting the given syntax, but except for this small issue LGTM ✅

@bmrobin
Copy link
Contributor Author

bmrobin commented Aug 8, 2023

@Nusnus noted. i tried what the "contributing" guide suggested with make test but i got a bunch of assertion failures when running on main (not my branch), so i decided to see what your CI on Github Actions would result in.

i ran the test i wrote locally on py3.11 but i'll check with tox now

@Nusnus
Copy link
Member

Nusnus commented Aug 8, 2023

@Nusnus noted. i tried what the "contributing" guide suggested with make test but i got a bunch of assertion failures when running on main (not my branch), so i decided to see what your CI on Github Actions would result in.

Can you link me the guide you followed? I'd be happy to review it.

i ran the test i wrote locally on py3.11 but i'll check with tox now

Awesome thanks!

@Nusnus Nusnus self-requested a review August 8, 2023 14:46
t/unit/app/test_beat.py Outdated Show resolved Hide resolved
@Nusnus Nusnus merged commit d1273af into celery:main Aug 8, 2023
30 checks passed
@Nusnus
Copy link
Member

Nusnus commented Aug 8, 2023

Thank you ❤️

@auvipy auvipy added this to the 5.3.x milestone Aug 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

result.id is causing celery beat to fail when using transaction.on_commit()
3 participants