> Le 27 janv. 2016 à 00:59, Tim Graham <timogra...@gmail.com> a écrit :
> 
> Regarding the original issue -- in Claude's use case, he says that calling 
> django.setup() before unpickling is not doable, as an external tool is doing 
> the unpickling of model data. Should we say that unpickling model data from 
> non-Django code is no longer possible?

There's an inconsistency that bothers me in this case with the current 
implementation (unless I missed something — I didn't try it).

If the task's arguments include at least one model instance, this will 
implicitly trigger django.setup() and the code can use the ORM (and logging is 
set up correctly, etc.)

If the code is refactored to pass the instance id in argument and the task 
function attempts to load the corresponding instance from the database, it will 
raise an exception when attempting to import the model.

This inconsistency sounds surprising and hard to diagnose. I'm not convinced 
special casing the situation where a model in passed in argument is the right 
choice.

I understand that the most obvious place to call django.setup() is at the top 
of the task function and at this point arguments have already been unpickled. 
This explains how we came up with the current code. We didn't realize that 
"unpickle a model before app loading has completed" could happen in other 
scenarios.

Regardless, I'm skeptical of this hack. I would expect task runners to provide 
some sort of initialization hook.

For rq, the documentation explains how to "provide your own worker script" to 
run initialization code. I believe this is something django-rq could easily 
abstract.

-- 
Aymeric.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/2CEA8A48-18C8-4FB1-A965-A14C6B6E5A4D%40polytechnique.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to