#25296: Failed Manager.create pollutes related models cache
-------------------------------+--------------------
Reporter: rubendura | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
After updating to 1.8.4 one of my tests broke. Digging down I found in my
codebase something along the lines of
{{{
try:
Token.objects.get_or_create(user=user)
except ValueError:
# The user does not yet exist
pass
}}}
The user might or might not be saved before reaching that block of code.
In case the user hasn't been created in the database get_or_create would
raise ValueError and accessing user.token would raise an exception (or in
this case, sending that user into a django-rest-framework's serializer
would output None in the token field, which is our expected behaviour).
After 1.8.4 ValueError is still raised, but an usaved token is cached in
user._token_cache, so accessing user.token now returns an object I didn't
expect, thus returning an invalid value from the serializer.
I believe this has something to do with ticket #25160.
On my side it's an easy fix (check the user before calling
Token.objects.create), but I don't know if this should be flagged as a bug
and it caught me off guard, so I thought I would be a good idea reporting
it just in case that was an unexpected side effect.
--
Ticket URL: <https://code.djangoproject.com/ticket/25296>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.1def4996c718034a1926ba684e557326%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.