-
Notifications
You must be signed in to change notification settings - Fork 211
Fix properties default value #281
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please check the follow failure
properties = getattr(request, 'properties') or {}
E AttributeError: 'Request' object has no attribute 'properties'
django_celery_results/backends/database.py:43: AttributeError
=========================== short test summary info ============================
FAILED t/unit/backends/test_database.py::test_DatabaseBackend::test_backend__pickle_serialization__dict_result
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
========================= 1 failed, 7 passed in 1.03s ==========================
@lvelvee can you also check it please? |
Sorry, I forgot that |
@KOliver94 could you please describe when the properties will be None? For robustness, you can add some bounds checking statements. |
By the way, let's see if |
@@ -45,7 +45,7 @@ def _create_request(self, task_id, name, args, kwargs, | |||
) | |||
if task_protocol == 1: | |||
body, headers, _, _ = hybrid_to_proto2(msg, msg.body) | |||
properties = {} | |||
properties = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about None or {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this field to reflect the problem and create a more edge-case like scenario when the properties field are present but with None
value.
@lvelvee I don't exactly know why are the properties @override_settings(CELERY_TASK_ALWAYS_EAGER=True)
@conditional_override_settings(
EMAIL_BACKEND="tests.helpers.test_utils.CombinedEmailBackend", CONDITION=EMAIL_FILE
)
@pytest.mark.django_db
def test_contact_message_email_sent_without_captcha(api_client, disable_recaptcha):
data = {
"name": "Joe Bloggs",
"email": "joe@example.com",
"message": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer posuere tempus nibh et lobortis.",
}
response = api_client.post("/api/v1/misc/contact", data)
assert response.status_code == status.HTTP_201_CREATED This test calls a Django REST Framework endpoint with a POST call which validates the data and calls the def perform_create(self, serializer):
name = serializer.data["name"]
email = serializer.data["email"]
message = serializer.data["message"]
email_contact_message.delay(name, email, message) @shared_task
def email_contact_message(name, email, message):
context = {
"name": name,
"message": message,
}
msg_plain = render_to_string("email/txt/contact_message.txt", context)
msg_html = render_to_string("email/html/contact_message.html", context)
subject = "Kapcsolatfelvétel | Budavári Schönherz Stúdió"
msg = (
EmailMultiAlternatives(
subject=subject,
body=msg_plain,
to=[email],
cc=[settings.DEFAULT_REPLY_EMAIL],
reply_to=[settings.DEFAULT_REPLY_EMAIL],
)
if not settings.DEBUG_EMAIL
else debug_email(subject, msg_plain)
)
msg.attach_alternative(msg_html, "text/html")
msg.send()
return f"Contact message from {name} was sent successfully." After this function got executed
According to the PyCharm debugger there are properties field in the object with
|
Could you please trim the code to a Minimal Reproducible Example with version-locked for locating the reason better? |
@lvelvee Here is my small demo: https://github.com/KOliver94/django-celery-results-bug-demo. Hope it helps. There is only one test under |
properties will be None if |
Good to know, thanks @lvelvee. However, it is still an unhandled exception in this package, am I right? |
please add yourself to author list & have a release note entry for the change made |
Hi @auvipy, What do you mean by the release note entry? Should I add it as an unreleased version to the |
I checked it and I don't think a release note would be needed for this case because this issue was introduced by #261 which is an unreleased feature. If you would like I can add it anyway but in my opinion it would be strange to have an entry in the release note regarding a bug fix when the bug was not present in the last version. |
make sense |
As I can see the value of
properties
should always be a dictionary. For this reason we don't need to handle any falsy values just set it as an empty dictionary if it does not have a valid value.Fixes #280