Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#14025 closed (fixed)

Flush command not fully supporting multi database support

Reported by: linovia Owned by: linovia
Component: Uncategorized Version: 1.2
Severity: Keywords:
Cc: xordoquy@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Flush has not been reworked with multi database

Story:

If one use two different databases (ie, with different models in both) flush emits the emit_post_sync_signal on EVERY model for EVERY database.
However since models may not be present (no django_site on legacy databases for example) an exception is raised which in turn breaks tests.

I ran into this even if I had no fixtures or no database access:

ERROR: test_basic_addition (modulemanagement.tests.SimpleTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/test/testcases.py", line 256, in __call__
    self._pre_setup()
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/test/testcases.py", line 223, in _pre_setup
    self._fixture_setup()
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/test/testcases.py", line 487, in _fixture_setup
    return super(TestCase, self)._fixture_setup()
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/test/testcases.py", line 235, in _fixture_setup
    call_command('flush', verbosity=0, interactive=False, database=db)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/core/management/__init__.py", line 166, in call_command
    return klass.execute(*args, **defaults)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/core/management/base.py", line 218, in execute
    output = self.handle(*args, **options)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/core/management/base.py", line 347, in handle
    return self.handle_noargs(**options)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/core/management/commands/flush.py", line 69, in handle_noargs
    emit_post_sync_signal(models.get_models(), verbosity, interactive, db)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/core/management/sql.py", line 185, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/dispatch/dispatcher.py", line 162, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/contrib/sites/management.py", line 14, in create_default_site
    s.save(using=db)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/contrib/sites/models.py", line 46, in save
    super(Site, self).save(*args, **kwargs)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/base.py", line 435, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/base.py", line 528, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/query.py", line 1479, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/sql/compiler.py", line 783, in execute_sql
    cursor = super(SQLInsertCompiler, self).execute_sql(None)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/models/sql/compiler.py", line 727, in execute_sql
    cursor.execute(sql, params)
  File "/virtualenvs/django1.2/lib/python2.6/site-packages/Django-1.2.1-py2.6.egg/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
    return self.cursor.execute(query, args)
DatabaseError: relation "django_site" does not exist

Attachments (2)

flush.patch (717 bytes ) - added by linovia 14 years ago.
flush-multi-db.diff (1.3 KB ) - added by linovia 14 years ago.
Patch for Flush command to support multi database more correctly

Download all attachments as: .zip

Change History (10)

by linovia, 14 years ago

Attachment: flush.patch added

comment:1 by linovia, 14 years ago

I apologize the patch isn't against the subversion trunk, I just don't have access to Django's trunk yet.
I'll update it tonight.

by linovia, 14 years ago

Attachment: flush-multi-db.diff added

Patch for Flush command to support multi database more correctly

comment:2 by linovia, 14 years ago

Has patch: set

Patch following the patch guideline added.

comment:3 by linovia, 14 years ago

Owner: changed from nobody to linovia
Status: newassigned

comment:4 by linovia, 14 years ago

Cc: xordoquy@… added

comment:5 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [13466]) Fixed #14025 -- Modified flush to adhere to router sync instructions when emmiting post-sync signals. Thanks to linovia for the patch.

comment:6 by Russell Keith-Magee, 14 years ago

(In [13467]) [1.2.X] Fixed #14025 -- Modified flush to adhere to router sync instructions when emmiting post-sync signals. Thanks to linovia for the patch.

Backport of r13466 from trunk.

comment:7 by Russell Keith-Magee, 14 years ago

(In [13471]) Corrected fix committed in r13466. Refs #14025.

comment:8 by Russell Keith-Magee, 14 years ago

(In [13472]) [1.2.X] Corrected fix committed in r13466. Refs #14025.

Backport of r13471 from trunk.

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