Opened 6 years ago

Closed 5 years ago

Last modified 5 years ago

#15633 closed Bug (fixed)

Bad documentation of post_syncdb signal

Reported by: Vlastimil Zíma Owned by: Justin Lilly
Component: Documentation Version: master
Severity: Normal Keywords:
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

Signal post_sycndb is badly documented:

  • documentation says that created_models is list, but emit_post_sync_signal is called with set when it is called from syncdb command. Surprisingly it is called with set from flush command, so there is probably error in code as well.
  • documentation suggests that post_syncdb signal is called only when table is created, so it looks like you can use it to change database structure (create contraints, triggers, ...) These SQL fail when yout post_sycndb handler is called from flush, because flush does not change database structure (except SQLs with 'IF NOT EXISTS'-like conditions). Documentation should noted that handlers of this signal should not change database structure and for such cases customize sql hack in syncdb should be used.

Change History (13)

comment:1 Changed 6 years ago by Vlastimil Zíma

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

Bug in description: flush command calls emit_post_sync_signal with list of models as in documentation

comment:2 Changed 6 years ago by Luke Plant

Type: Bug

comment:3 Changed 6 years ago by Luke Plant

Severity: Normal

comment:4 Changed 6 years ago by Gabriel Hurley

Triage Stage: UnreviewedAccepted

comment:5 Changed 5 years ago by Ramiro Morales

Easy pickings: unset
UI/UX: unset

Seems to be a duplicate of #5848 -- but this ticket was opened on Mach 17 2011 against trunk and the other ticket was fixed on Sep 12 2010.

comment:6 in reply to:  5 Changed 5 years ago by Vlastimil Zíma

Replying to ramiro:

Seems to be a duplicate of #5848 -- but this ticket was opened on Mach 17 2011 against trunk and the other ticket was fixed on Sep 12 2010.

I probably missed that, but the second point is still valid.

comment:7 Changed 5 years ago by Aymeric Augustin

Regarding your second point, there's already a solution for this problem, see https://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data

comment:8 in reply to:  7 Changed 5 years ago by Vlastimil Zíma

Replying to aaugustin:

Regarding your second point, there's already a solution for this problem, see https://docs.djangoproject.com/en/dev/howto/initial-data/#providing-initial-sql-data

This does not work one would expected from documentation.

If I create initial SQL like

ALTER TABLE "some_table"
    ADD CONSTRAINT "some_table_constraint1" CHECK (some_column = 45);

This will make flush command fail, as it emits post_syncdb signal marking that table is created (but it is not). This can be sometimes prevented using IF NOT EXISTS condition, but not always.

comment:9 Changed 5 years ago by Justin Lilly

Owner: changed from nobody to Justin Lilly
Status: newassigned

comment:10 Changed 5 years ago by anonymous

Has patch: set

comment:11 Changed 5 years ago by Preston Holmes

Triage Stage: AcceptedReady for checkin

applied - built docs, reads well

comment:12 Changed 5 years ago by Paul McMillan

Resolution: fixed
Status: assignedclosed

In [16874]:

Fixed #15633 -- Improved docs for post_syncdb signal.

comment:13 Changed 5 years ago by Paul McMillan

In [16879]:

[1.3.X] Fixed #15633 -- Improved docs for post_syncdb signal. Thanks Justin Lilly for the patch.

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