Django

Code

Ticket #7597 (closed: fixed)

Opened 6 months ago

Last modified 6 months ago

syncdb fails if the loaddata management command is called in a post_syncdb handler

Reported by: keithb Assigned to: keithb
Milestone: Component: Uncategorized
Version: SVN Keywords:
Cc: kbussell@gmail.com Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Calling management.call_command('loaddata', ...) from within a post_syncdb handler will cause all subsequent SQL to fail. This broke as of r7803.

models.py:

class Book(models.Model):
    title = models.CharField(max_length=255, db_index=True)

management.py:

def post_syncdb(sender, created_models):
    if models.Book in created_models:    
        management.call_command('loaddata', 'data.json')
dispatcher.connect(post_syncdb, sender=models, signal=signals.post_syncdb)

data.json:

[{"pk": 1, "model": "app1.book", "fields": {"title": "This is a test"}}]
> manage.py syncdb
Creating table app1_book
Installing json fixture 'data' from 'C:\source\test\app1\fixtures'.
Installed 1 object(s) from 1 fixture(s)
Installing index for app1.Book model
Failed to install index for app1.Book model: cursor already closed

Attachments

syncdb_connection_fix.diff (0.6 kB) - added by keithb on 07/01/08 20:40:16.
actual fix

Change History

07/01/08 18:51:10 changed by keithb

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Forgot to mention, in case it's relevant: using the postgresql_psycopg2 engine against PostgreSQL 8.3.

07/01/08 19:15:17 changed by keithb

  • owner changed from nobody to keithb.
  • status changed from new to assigned.
  • has_patch set to 1.

Added a simple patch to fix this.

07/01/08 20:40:16 changed by keithb

  • attachment syncdb_connection_fix.diff added.

actual fix

07/11/08 09:07:00 changed by russellm

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7889]) Fixed #7597 -- Added code to force the re-opening of the cursor connection, just in case a post-syncdb handler closes it. Thanks to keithb for the report and fix.


Add/Change #7597 (syncdb fails if the loaddata management command is called in a post_syncdb handler)




Change Properties
Action