﻿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
24007	Unable to unpickle models from an external script	Claude Paroz	nobody	"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?"	Bug	closed	Core (Other)	1.7	Normal	wontfix			Accepted	1	0	0	0	0	0
