Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #11428 -- Ensured that SQL generating commands and dumpdata don…

…'t include proxy models in their output. Thanks to Anssi Kaariainen for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11343 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3412860f89a1f72257037c19c06beebc92dd7e06 1 parent e00150a
@freakboy3742 freakboy3742 authored
View
3  django/core/management/commands/dumpdata.py
@@ -73,7 +73,8 @@ def handle(self, *app_labels, **options):
model_list = get_models(app)
for model in model_list:
- objects.extend(model._default_manager.all())
+ if not model._meta.proxy:
+ objects.extend(model._default_manager.all())
try:
return serializers.serialize(format, objects, indent=indent)
View
10 django/db/backends/creation.py
@@ -40,7 +40,7 @@ def sql_create_model(self, model, style, known_models=set()):
from django.db import models
opts = model._meta
- if not opts.managed:
+ if not opts.managed or opts.proxy:
return [], {}
final_output = []
table_output = []
@@ -121,7 +121,7 @@ def sql_for_pending_references(self, model, style, pending_references):
"Returns any ALTER TABLE statements to add constraints after the fact."
from django.db.backends.util import truncate_name
- if not model._meta.managed:
+ if not model._meta.managed or model._meta.proxy:
return []
qn = self.connection.ops.quote_name
final_output = []
@@ -236,7 +236,7 @@ def sql_for_inline_many_to_many_references(self, model, field, style):
def sql_indexes_for_model(self, model, style):
"Returns the CREATE INDEX SQL statements for a single model"
- if not model._meta.managed:
+ if not model._meta.managed or model._meta.proxy:
return []
output = []
for f in model._meta.local_fields:
@@ -268,7 +268,7 @@ def sql_indexes_for_field(self, model, f, style):
def sql_destroy_model(self, model, references_to_delete, style):
"Return the DROP TABLE and restraint dropping statements for a single model"
- if not model._meta.managed:
+ if not model._meta.managed or model._meta.proxy:
return []
# Drop the table now
qn = self.connection.ops.quote_name
@@ -286,7 +286,7 @@ def sql_destroy_model(self, model, references_to_delete, style):
def sql_remove_table_constraints(self, model, references_to_delete, style):
from django.db.backends.util import truncate_name
- if not model._meta.managed:
+ if not model._meta.managed or model._meta.proxy:
return []
output = []
qn = self.connection.ops.quote_name
View
24 tests/regressiontests/fixtures_regress/models.py
@@ -54,7 +54,7 @@ class Parent(models.Model):
class Child(Parent):
data = models.CharField(max_length=10)
-# Models to regresison check #7572
+# Models to regression test #7572
class Channel(models.Model):
name = models.CharField(max_length=255)
@@ -65,6 +65,14 @@ class Article(models.Model):
class Meta:
ordering = ('id',)
+# Models to regression test #11428
+class Widget(models.Model):
+ name = models.CharField(max_length=255)
+
+class WidgetProxy(Widget):
+ class Meta:
+ proxy = True
+
__test__ = {'API_TESTS':"""
>>> from django.core import management
@@ -170,4 +178,18 @@ class Meta:
>>> management.call_command('dumpdata', 'fixtures_regress.animal', format='json')
[{"pk": 1, "model": "fixtures_regress.animal", "fields": {"count": 3, "weight": 1.2, "name": "Lion", "latin_name": "Panthera leo"}}, {"pk": 2, "model": "fixtures_regress.animal", "fields": {"count": 2, "weight": 2.29..., "name": "Platypus", "latin_name": "Ornithorhynchus anatinus"}}, {"pk": 10, "model": "fixtures_regress.animal", "fields": {"count": 42, "weight": 1.2, "name": "Emu", "latin_name": "Dromaius novaehollandiae"}}]
+###############################################
+# Regression for #11428 - Proxy models aren't included
+# when you run dumpdata over an entire app
+
+# Flush out the database first
+>>> management.call_command('reset', 'fixtures_regress', interactive=False, verbosity=0)
+
+# Create an instance of the concrete class
+>>> Widget(name='grommet').save()
+
+# Dump data for the entire app. The proxy class shouldn't be included
+>>> management.call_command('dumpdata', 'fixtures_regress', format='json')
+[{"pk": 1, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]
+
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.