Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed 21799 - Modified ignorenonexistent loaddata to ignore models #2335

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion django/core/serializers/python.py
Expand Up @@ -90,7 +90,13 @@ def Deserializer(object_list, **options):

for d in object_list:
# Look up the model and starting build a dict of data for it.
Model = _get_model(d["model"])
try:
Model = _get_model(d["model"])
except base.DeserializationError, e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would need to be as e for Python 3 compatibility, but I believe you can just raise in the except block with e, right?

if ignore:
continue
else:
raise e
data = {}
if 'pk' in d:
data[Model._meta.pk.attname] = Model._meta.pk.to_python(d.get("pk", None))
Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures_regress/fixtures/sequence_extra.json
Expand Up @@ -9,5 +9,16 @@
"count": 3,
"weight": 1.2
}
},
{
"pk": "1",
"model": "fixtures_regress.animal_extra",
"fields": {
"name": "Lion",
"extra_name": "Super Lion",
"latin_name": "Panthera leo",
"count": 3,
"weight": 1.2
}
}
]