#24007: Unable to unpickle models from an external script
----------------------------------------+------------------------
               Reporter:  claudep       |          Owner:  nobody
                   Type:  Bug           |         Status:  new
              Component:  Core (Other)  |        Version:  1.7
               Severity:  Normal        |       Keywords:
           Triage Stage:  Unreviewed    |      Has patch:  0
    Needs documentation:  0             |    Needs tests:  0
Patch needs improvement:  0             |  Easy pickings:  0
                  UI/UX:  0             |
----------------------------------------+------------------------
 I'm using Python rq stack to delegate some tasks from my Django app to a
 queued system. In some of those tasks, models are pickled and then
 unpickled by rq. Unfortunately, with Django 1.7, I'm getting
 `AppRegistryNotReady` errors:

 {{{
 Traceback (most recent call last):
   File "/usr/local/bin/rqworker", line 9, in <module>
     load_entry_point('rq==0.4.6', 'console_scripts', 'rqworker')()
   File "/usr/local/lib/python2.7/dist-packages/rq/scripts/rqworker.py",
 line 100, in main
     w.work(burst=args.burst)
   File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 358, in
 work
     self.execute_job(job)
   File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 422, in
 execute_job
     self.main_work_horse(job)
   File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 457, in
 main_work_horse
     success = self.perform_job(job)
   File "/usr/local/lib/python2.7/dist-packages/rq/worker.py", line 473, in
 perform_job
     job.func_name,
   File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 226, in
 func_name
     self._unpickle_data()
   File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 194, in
 _unpickle_data
     self._func_name, self._instance, self._args, self._kwargs =
 unpickle(self.data)
   File "/usr/local/lib/python2.7/dist-packages/rq/job.py", line 48, in
 unpickle
     obj = loads(pickled_string)
   File "/usr/local/lib/python2.7/dist-packages/django/db/models/base.py",
 line 1464, in model_unpickle
     model = apps.get_model(*model_id)
   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
 line 199, in get_model
     self.check_models_ready()
   File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py",
 line 131, in check_models_ready
     raise AppRegistryNotReady("Models aren't loaded yet.")
 django.core.exceptions.AppRegistryNotReady: (AppRegistryNotReady("Models
 aren't loaded yet.",), <function model_unpickle
 }}}

 As you can see in the stack trace, my code has no chance to fix this as it
 is not called before the unpickling process.

 One idea could be to check the app registry state in `model_unpickle` and
 populate it if needed. Thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/24007>
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/050.a9645a9398c164a0a55c6d01693b5728%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to