Skip to content

Commit 3412860

Browse files
committed
Fixed django#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
1 parent e00150a commit 3412860

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

django/core/management/commands/dumpdata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def handle(self, *app_labels, **options):
7373
model_list = get_models(app)
7474

7575
for model in model_list:
76-
objects.extend(model._default_manager.all())
76+
if not model._meta.proxy:
77+
objects.extend(model._default_manager.all())
7778

7879
try:
7980
return serializers.serialize(format, objects, indent=indent)

django/db/backends/creation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def sql_create_model(self, model, style, known_models=set()):
4040
from django.db import models
4141

4242
opts = model._meta
43-
if not opts.managed:
43+
if not opts.managed or opts.proxy:
4444
return [], {}
4545
final_output = []
4646
table_output = []
@@ -121,7 +121,7 @@ def sql_for_pending_references(self, model, style, pending_references):
121121
"Returns any ALTER TABLE statements to add constraints after the fact."
122122
from django.db.backends.util import truncate_name
123123

124-
if not model._meta.managed:
124+
if not model._meta.managed or model._meta.proxy:
125125
return []
126126
qn = self.connection.ops.quote_name
127127
final_output = []
@@ -236,7 +236,7 @@ def sql_for_inline_many_to_many_references(self, model, field, style):
236236

237237
def sql_indexes_for_model(self, model, style):
238238
"Returns the CREATE INDEX SQL statements for a single model"
239-
if not model._meta.managed:
239+
if not model._meta.managed or model._meta.proxy:
240240
return []
241241
output = []
242242
for f in model._meta.local_fields:
@@ -268,7 +268,7 @@ def sql_indexes_for_field(self, model, f, style):
268268

269269
def sql_destroy_model(self, model, references_to_delete, style):
270270
"Return the DROP TABLE and restraint dropping statements for a single model"
271-
if not model._meta.managed:
271+
if not model._meta.managed or model._meta.proxy:
272272
return []
273273
# Drop the table now
274274
qn = self.connection.ops.quote_name
@@ -286,7 +286,7 @@ def sql_destroy_model(self, model, references_to_delete, style):
286286
def sql_remove_table_constraints(self, model, references_to_delete, style):
287287
from django.db.backends.util import truncate_name
288288

289-
if not model._meta.managed:
289+
if not model._meta.managed or model._meta.proxy:
290290
return []
291291
output = []
292292
qn = self.connection.ops.quote_name

tests/regressiontests/fixtures_regress/models.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Parent(models.Model):
5454
class Child(Parent):
5555
data = models.CharField(max_length=10)
5656

57-
# Models to regresison check #7572
57+
# Models to regression test #7572
5858
class Channel(models.Model):
5959
name = models.CharField(max_length=255)
6060

@@ -65,6 +65,14 @@ class Article(models.Model):
6565
class Meta:
6666
ordering = ('id',)
6767

68+
# Models to regression test #11428
69+
class Widget(models.Model):
70+
name = models.CharField(max_length=255)
71+
72+
class WidgetProxy(Widget):
73+
class Meta:
74+
proxy = True
75+
6876
__test__ = {'API_TESTS':"""
6977
>>> from django.core import management
7078
@@ -170,4 +178,18 @@ class Meta:
170178
>>> management.call_command('dumpdata', 'fixtures_regress.animal', format='json')
171179
[{"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"}}]
172180
181+
###############################################
182+
# Regression for #11428 - Proxy models aren't included
183+
# when you run dumpdata over an entire app
184+
185+
# Flush out the database first
186+
>>> management.call_command('reset', 'fixtures_regress', interactive=False, verbosity=0)
187+
188+
# Create an instance of the concrete class
189+
>>> Widget(name='grommet').save()
190+
191+
# Dump data for the entire app. The proxy class shouldn't be included
192+
>>> management.call_command('dumpdata', 'fixtures_regress', format='json')
193+
[{"pk": 1, "model": "fixtures_regress.widget", "fields": {"name": "grommet"}}]
194+
173195
"""}

0 commit comments

Comments
 (0)