Opened 17 years ago

Closed 14 years ago

#5848 closed (fixed)

post_syncdb signal callbacks: argument 'created_models' is sometimes a list, sometimes a set

Reported by: sam@… Owned by: nobody
Component: Core (Other) Version: dev
Severity: Keywords: post_syncdb signal created_models
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a function hooked up to the post_syncdb signal. When the function is called as a result of running the 'syncdb' management command, the created_models argument is a set. But when the function is called from the 'flush' management command, the created_models argument is a list.

def type_test (sender, app, created_models, verbosity, interactive):
    print type (created_models)
dispatcher.connect (type_test, signal = signals.post_syncdb)
$ p/manage.py test
...
<type 'set'>
<type 'set'>
<type 'set'>
...
<type 'list'>
<type 'list'>
<type 'list'>

This is a problem because one of my functions checks to see if it actually has to do something with a for loop that looks like for m in created_models.intersection (django.db.models.get_models (app)). I don't mind changing that to something that works with both lists and sets, but it would be nice if this inconsistency was cleaned up anyway.

Attachments (2)

5848.core.management.commands.flush.diff (1.0 KB ) - added by Pete Crosier 17 years ago.
Make flush use set for created_models
5848.core.management.commands.syncdb.diff (629 bytes ) - added by Pete Crosier 17 years ago.
Make syncdb use a list for created_models instead

Download all attachments as: .zip

Change History (9)

comment:1 by anonymous, 17 years ago

Summary: post_syncdb signal callbacks: argument 'created_models' is sometimes a list, sometimes an strpost_syncdb signal callbacks: argument 'created_models' is sometimes a list, sometimes a set

comment:2 by Pete Crosier, 17 years ago

Has patch: set
Keywords: post_syncdb signal created_models added

by Pete Crosier, 17 years ago

Make flush use set for created_models

comment:3 by Chris Beaven, 17 years ago

Component: UncategorizedCore framework
Triage Stage: UnreviewedDesign decision needed

Perhaps the syncdb signal should be made to return a list instead?

by Pete Crosier, 17 years ago

Make syncdb use a list for created_models instead

comment:4 by Pete Crosier, 17 years ago

That does make more sense (also, the wiki says to expect created_models as a list) - patch attached.

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

Triage Stage: Design decision neededAccepted

This should be a set. It's not ordered, you can't have duplicates, and membership of collection is an important operation.

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

Triage Stage: AcceptedReady for checkin

Actually -- looking at the patch, it's pretty much RFC, although the patch needs to be updated (since the Python 2.3 protection is no longer required).

comment:7 by Malcolm Tredinnick, 14 years ago

Resolution: fixed
Status: newclosed

(In [13768]) Always pass models in post_syncdb signals as a set (not as a list
sometimes).

Fixed #5848, thanks to PJCrosier.

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