﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
25296	Failed Manager.create() could pollute related models cache	Rubén Durá Tarí	Raphael Merx	"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."	Bug	closed	Database layer (models, ORM)	1.8	Normal	fixed			Accepted	0	0	0	0	0	0
