Opened 7 years ago

Closed 7 years ago

#7597 closed (fixed)

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

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

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 (1)

syncdb_connection_fix.diff (625 bytes) - added by keithb 7 years ago.
actual fix

Download all attachments as: .zip

Change History (4)

comment:1 Changed 7 years ago by keithb

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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

comment:2 Changed 7 years ago by keithb

  • Has patch set
  • Owner changed from nobody to keithb
  • Status changed from new to assigned

Added a simple patch to fix this.

Changed 7 years ago by keithb

actual fix

comment:3 Changed 7 years ago by russellm

  • Resolution set to fixed
  • Status changed from assigned to closed

(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.

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