Django yubin celery bypass backend and management commands#69
Django yubin celery bypass backend and management commands#69
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #69 +/- ##
==========================================
+ Coverage 99.18% 99.27% +0.08%
==========================================
Files 27 34 +7
Lines 736 826 +90
Branches 87 92 +5
==========================================
+ Hits 730 820 +90
Misses 4 4
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
579d925 to
cc2712f
Compare
f11847d to
98a32f5
Compare
|
@Coperh squash your commits and reference in your commit message the github issue in order to describe what you're doing |
e3f055b to
ba5c1f6
Compare
CharString
left a comment
There was a problem hiding this comment.
I'm not sure I understand the locking tests fully.
My underbelly would reach for a stateful property based test of the behaviour of the whole system. Generate actions and (failure) events, and have a simple model of what we expect (could be a few list[Message] as queues) and then if there is no sequential order for these actions that we did in parallel, than something is wrong with the system.
Or alternatively. Unittest the lock parts more tightly instead of trying to get the whole call_command chain testable. There are many moving parts there.
|
BTW, |
d237d51 to
02e2513
Compare
CharString
left a comment
There was a problem hiding this comment.
Nice. Looking forward to replace my implementation with this. Just had an insight (I think) for some simplification.
b2966e1 to
af84718
Compare
|
Removed TBD: squash commits |
e44e536 to
ba43f61
Compare
|
@sergei-maertens wil jij deze als hoeder van django-common mergen? |
I see I have some pending review comments, I'll set aside some time this week hopefully. Please remind me if I forget. |
sergei-maertens
left a comment
There was a problem hiding this comment.
My main concern here is that django-yubin will still pull in the celery dependency, and there is code here and there that detects availability of Celery based on the import succeeding or not. I'm afraid that there will still be situations where errors pop up because some thing is trying to dispatch a celery task while it's not configured. Is that addressed in any way?
| "django-stubs", | ||
| "decouple-types", | ||
| "redis", | ||
| "freezegun", |
There was a problem hiding this comment.
Can you try https://github.com/adamchainz/time-machine instead? There's a blog post describing why it's better and should replace freezegun usage.
| ] | ||
| yubin = [ | ||
| "django-yubin>=2.0.0", | ||
| "filelock", |
There was a problem hiding this comment.
do we need to take containerized applications into account that may not have a shared file system where the lock file is created?
| YUBIN_LOCK_PATH: Path = Path("/tmp") / "send_mail" | ||
| YUBIN_LOCK_WAIT_TIMEOUT: int = 0 |
There was a problem hiding this comment.
can you properly prefix the settings with MKN_ so that it's clear these are our own settings and not to be confused with the actual django-yubin?
| try: | ||
| import django_yubin | ||
| except ImportError: | ||
| django_yubin = None |
There was a problem hiding this comment.
Please use the importlib way of detecting installed libraries instead, it's the recommended approach.
| health_checks | ||
| otel | ||
| apis | ||
| yubin |
There was a problem hiding this comment.
I'd argue that the settings documentation is going to be read more often than the Yubin workaround, so I'd move this down in the toc tree below settings.
| """ | ||
| Tests original Message.enqueue functionality | ||
| Should not mark the message as enqueued if not allowed | ||
| """ |
There was a problem hiding this comment.
This confuses me. To me, the original is Message.enqueue, but that's not being called here, instead the separate function is being called. Is the intent to replace/monkeypatch the model method? If not, what happens if some code calls the model method instead of going through the custom function?
There was a problem hiding this comment.
I really also want to see test docstrings in the form of:
Assert that X happens when Y...
this also applies to the test name itself. Now if you read the test name, it implies that enqueue can never actually queue the message, but clearly there are some conditions to take into account.
| # yubin does not correctly use django settings | ||
| from django_yubin import settings | ||
|
|
||
| settings.MAILER_TEST_MODE = True | ||
| settings.MAILER_TEST_EMAIL = "test_mailer@example.com,test_mailer2@example.com" |
There was a problem hiding this comment.
does this correctly reset the settings after the test exits? This looks like a broken test isolation problem for future tests being added.
sergei-maertens
left a comment
There was a problem hiding this comment.
My main concern here is that django-yubin will still pull in the celery dependency, and there is code here and there that detects availability of Celery based on the import succeeding or not. I'm afraid that there will still be situations where errors pop up because some thing is trying to dispatch a celery task while it's not configured. Is that addressed in any way?
Co-authored-by: Chris Wesseling <chris.wesseling@protonmail.com>
Co-authored-by: Sergei Maertens <sergei-maertens@users.noreply.github.com>
fdb5c4f to
deff661
Compare
deff661 to
4771f6b
Compare
|
I think I addressed all of the comments |
|
An issue I found with the non-monkeypatched way is that yubin does run My bypass is to patch like here: from django_yubin import tasks
tasks.send_email.delay = lambda *args, **kwargs: None |
Message.enqueue,Message.retry_messagesmethods anddjango_yubin.queue_email_messageand replaces the celery tasksdjango_yubin.backends.QueuedEmailBackendand replaces with modifiedqueue_email_messagemaykin_common.yubin.engine.send_allto manually send yubin Messages