Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#16861 closed Bug (invalid)

Fixtures do not work with namespaced apps

Reported by: jlsherrill@… Owned by: nobody
Component: Uncategorized Version: 1.3
Severity: Normal Keywords:
Cc: jlsherrill@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If you have an app that is "foo.bar" instead of just "foo" it seems as if it is impossible to create fixtures for them. For example the app django-allauth includes multiples apps within it:

  • allauth.facebook
  • allauth.twitter
  • etc..

You can use it just fine, but if you try to use a fixture, for example:

- model: allauth.facebook.models.FacebookApp     #  (same error with allauth.facebook.FacebookApp)
  pk: 1
  fields:
    name: TestApp
    site: "1"
    application_id: 1234
    api_key: Foo
    application_secret: FOOO

importing will fail with this traceback:

Problem installing fixture '~/project/settings/../../local_apps/accounts/fixtures/initial_data.yaml': Traceback (most recent call last):
  File "~/beer-env/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 169, in handle
    for obj in objects:
  File "~/beer-env/lib/python2.7/site-packages/django/core/serializers/pyyaml.py", line 54, in Deserializer
    for obj in PythonDeserializer(yaml.load(stream), **options):
  File "~/beer-env/lib/python2.7/site-packages/django/core/serializers/python.py", line 84, in Deserializer
    Model = _get_model(d["model"])
  File "~/beer-env/lib/python2.7/site-packages/django/core/serializers/python.py", line 142, in _get_model
    raise base.DeserializationError(u"Invalid model identifier: '%s'" % model_identifier)
DeserializationError: Invalid model identifier: 'allauth.FacebookApp'

It seems that the get_model() call within _get_model() of /django/core/serializers/python.py is splitting the 'model' from the fixture which doesn't seem correct.

Affected code (/django/core/serializers/python.py)

def _get_model(model_identifier):
    """
    Helper to look up a model from an "app_label.module_name" string.
    """
    try:
        #import pdb; pdb.set_trace()
        Model = models.get_model(*model_identifier.split("."))
    except TypeError:
        Model = None
    if Model is None:
        raise base.DeserializationError(u"Invalid model identifier: '%s'" % model_identifier)
    return Model

Change History (2)

comment:1 by Carl Meyer, 13 years ago

Resolution: invalid
Status: newclosed

Models in fixtures are referred to by "app_label.ModelName", where "app_label" is the final component of the app's dotted path (same as what you'd pass to e.g. "manage.py dumpdata"). So the string you're looking for is "facebook.FacebookApp" - "allauth" should be omitted entirely.

comment:2 by anonymous, 13 years ago

Ahhh. Thanks! That worked just fine.

Note: See TracTickets for help on using tickets.
Back to Top