Code

Opened 7 years ago

Closed 4 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: master
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: UI/UX:

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 PJCrosier 6 years ago.
Make flush use set for created_models
5848.core.management.commands.syncdb.diff (629 bytes) - added by PJCrosier 6 years ago.
Make syncdb use a list for created_models instead

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from post_syncdb signal callbacks: argument 'created_models' is sometimes a list, sometimes an str to post_syncdb signal callbacks: argument 'created_models' is sometimes a list, sometimes a set

comment:2 Changed 6 years ago by PJCrosier

  • Has patch set
  • Keywords post_syncdb signal created_models added

Changed 6 years ago by PJCrosier

Make flush use set for created_models

comment:3 Changed 6 years ago by SmileyChris

  • Component changed from Uncategorized to Core framework
  • Triage Stage changed from Unreviewed to Design decision needed

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

Changed 6 years ago by PJCrosier

Make syncdb use a list for created_models instead

comment:4 Changed 6 years ago by PJCrosier

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

comment:5 Changed 4 years ago by russellm

  • Triage Stage changed from Design decision needed to Accepted

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

comment:6 Changed 4 years ago by russellm

  • Triage Stage changed from Accepted to Ready 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 Changed 4 years ago by mtredinnick

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

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

Fixed #5848, thanks to PJCrosier.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.