Author: russellm Date: 2009-07-11 09:22:52 -0500 (Sat, 11 Jul 2009) New Revision: 11215
Added: django/trunk/tests/regressiontests/m2m_through_regress/fixtures/ django/trunk/tests/regressiontests/m2m_through_regress/fixtures/m2m_through.json Modified: django/trunk/AUTHORS django/trunk/django/db/backends/oracle/base.py django/trunk/django/db/backends/postgresql/operations.py django/trunk/tests/regressiontests/m2m_through_regress/models.py Log: Fixed #11107 -- Corrected the generation of sequence reset SQL for m2m fields with an intermediate model. Thanks to J Clifford Dyer for the report and fix. Modified: django/trunk/AUTHORS =================================================================== --- django/trunk/AUTHORS 2009-07-11 02:00:34 UTC (rev 11214) +++ django/trunk/AUTHORS 2009-07-11 14:22:52 UTC (rev 11215) @@ -131,6 +131,7 @@ Andrew Durdin <adur...@gmail.com> d...@woofle.net Andy Dustman <farcep...@gmail.com> + J. Clifford Dyer <j...@unc.edu> Clint Ecker Nick Efford <n...@efford.org> eib...@gmail.com Modified: django/trunk/django/db/backends/oracle/base.py =================================================================== --- django/trunk/django/db/backends/oracle/base.py 2009-07-11 02:00:34 UTC (rev 11214) +++ django/trunk/django/db/backends/oracle/base.py 2009-07-11 14:22:52 UTC (rev 11215) @@ -217,12 +217,13 @@ # continue to loop break for f in model._meta.many_to_many: - table_name = self.quote_name(f.m2m_db_table()) - sequence_name = get_sequence_name(f.m2m_db_table()) - column_name = self.quote_name('id') - output.append(query % {'sequence': sequence_name, - 'table': table_name, - 'column': column_name}) + if not f.rel.through: + table_name = self.quote_name(f.m2m_db_table()) + sequence_name = get_sequence_name(f.m2m_db_table()) + column_name = self.quote_name('id') + output.append(query % {'sequence': sequence_name, + 'table': table_name, + 'column': column_name}) return output def start_transaction_sql(self): Modified: django/trunk/django/db/backends/postgresql/operations.py =================================================================== --- django/trunk/django/db/backends/postgresql/operations.py 2009-07-11 02:00:34 UTC (rev 11214) +++ django/trunk/django/db/backends/postgresql/operations.py 2009-07-11 14:22:52 UTC (rev 11215) @@ -121,14 +121,15 @@ style.SQL_TABLE(qn(model._meta.db_table)))) break # Only one AutoField is allowed per model, so don't bother continuing. for f in model._meta.many_to_many: - output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ - (style.SQL_KEYWORD('SELECT'), - style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), - style.SQL_FIELD(qn('id')), - style.SQL_FIELD(qn('id')), - style.SQL_KEYWORD('IS NOT'), - style.SQL_KEYWORD('FROM'), - style.SQL_TABLE(qn(f.m2m_db_table())))) + if not f.rel.through: + output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ + (style.SQL_KEYWORD('SELECT'), + style.SQL_FIELD(qn('%s_id_seq' % f.m2m_db_table())), + style.SQL_FIELD(qn('id')), + style.SQL_FIELD(qn('id')), + style.SQL_KEYWORD('IS NOT'), + style.SQL_KEYWORD('FROM'), + style.SQL_TABLE(qn(f.m2m_db_table())))) return output def savepoint_create_sql(self, sid): Added: django/trunk/tests/regressiontests/m2m_through_regress/fixtures/m2m_through.json =================================================================== --- django/trunk/tests/regressiontests/m2m_through_regress/fixtures/m2m_through.json (rev 0) +++ django/trunk/tests/regressiontests/m2m_through_regress/fixtures/m2m_through.json 2009-07-11 14:22:52 UTC (rev 11215) @@ -0,0 +1,34 @@ +[ + { + "pk": "1", + "model": "m2m_through_regress.person", + "fields": { + "name": "Guido" + } + }, + { + "pk": "1", + "model": "auth.user", + "fields": { + "username": "Guido", + "email": "b...@python.org", + "password": "abcde" + } + }, + { + "pk": "1", + "model": "m2m_through_regress.group", + "fields": { + "name": "Python Core Group" + } + }, + { + "pk": "1", + "model": "m2m_through_regress.usermembership", + "fields": { + "user": "1", + "group": "1", + "price": "100" + } + } +] \ No newline at end of file Modified: django/trunk/tests/regressiontests/m2m_through_regress/models.py =================================================================== --- django/trunk/tests/regressiontests/m2m_through_regress/models.py 2009-07-11 02:00:34 UTC (rev 11214) +++ django/trunk/tests/regressiontests/m2m_through_regress/models.py 2009-07-11 14:22:52 UTC (rev 11215) @@ -12,7 +12,9 @@ def __unicode__(self): return "%s is a member of %s" % (self.person.name, self.group.name) +# using custom id column to test ticket #11107 class UserMembership(models.Model): + id = models.AutoField(db_column='usermembership_id', primary_key=True) user = models.ForeignKey(User) group = models.ForeignKey('Group') price = models.IntegerField(default=100) @@ -196,4 +198,12 @@ # Flush the database, just to make sure we can. >>> management.call_command('flush', verbosity=0, interactive=False) +## Regression test for #11107 +Ensure that sequences on m2m_through tables are being created for the through +model, not for a phantom auto-generated m2m table. + +>>> management.call_command('loaddata', 'm2m_through', verbosity=0) +>>> management.call_command('dumpdata', 'm2m_through_regress', format='json') +[{"pk": 1, "model": "m2m_through_regress.usermembership", "fields": {"price": 100, "group": 1, "user": 1}}, {"pk": 1, "model": "m2m_through_regress.person", "fields": {"name": "Guido"}}, {"pk": 1, "model": "m2m_through_regress.group", "fields": {"name": "Python Core Group"}}] + """} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-updates?hl=en -~----------~----~----~----~------~----~------~--~---