Signal limitations with custom models!

31 views
Skip to first unread message

Uzair Tariq

unread,
May 17, 2017, 10:59:24 AM5/17/17
to Django users
So i read about Signal Limitations in Django that comes up with user custom models and you can't use get_user_model() as according to this link it's clearly stated that the reason for it is because the module is not completely loaded at this point and the solution is to defer the function call until the whole module is loaded. So why not this case does not apply to Default user model i.e. AbstractUser in django? Is it because of execution order or is it some back end One Time execution logic that loads the default models only once in a cache and retrieves it every time but not in custom user model case?

James Schneider

unread,
May 17, 2017, 5:53:57 PM5/17/17
to django...@googlegroups.com


On May 17, 2017 7:59 AM, "Uzair Tariq" <s.uzai...@gmail.com> wrote:
So i read about Signal Limitations in Django that comes up with user custom models and you can't use get_user_model() as according to this link it's clearly stated that the reason for it is because the module is not completely loaded at this point and the solution is to defer the function call until the whole module is loaded. So why not this case does not apply to Default user model i.e. AbstractUser in django? Is it because of execution order or is it some back end One Time execution logic that loads the default models only once in a cache and retrieves it every time but not in custom user model case?

From my brief reading of the ticket, it looks like the signal call for the built-in User (not AbstractUser, which is never directly used) only works because that model is already loaded by the time the custom models are inspected. 

My guess is that the internal Django models are loaded first, and then app models are loaded. Since you're defining the signal handler in your app, you would be able to reference the built-in models but not any models that haven't already been inspected. 

I doubt there is any magic involved, it's technically a race condition.

Admittedly, I'm not deeply familiar with the mechanics in this scenario, but it's my best educated guess.

-James


Uzair Tariq

unread,
May 18, 2017, 11:08:41 AM5/18/17
to Django users
Thanks man! Actually i was thinking the same thing as mentioned in the question because that's the only valid logical reason i can come up with after viewing the ticket. Anyways Thanks again
Reply all
Reply to author
Forward
0 new messages