Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#15633 closed Bug (fixed)

Bad documentation of post_syncdb signal

Reported by: vzima Owned by: justinlilly
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 4 years ago by vzima

  • 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 4 years ago by lukeplant

  • Type set to Bug

comment:3 Changed 4 years ago by lukeplant

  • Severity set to Normal

comment:4 Changed 4 years ago by gabrielhurley

  • Triage Stage changed from Unreviewed to Accepted

comment:5 follow-up: Changed 4 years ago by ramiro

  • 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 4 years ago by vzima

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 follow-up: Changed 4 years ago by 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

comment:8 in reply to: ↑ 7 Changed 4 years ago by vzima

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 3 years ago by justinlilly

  • Owner changed from nobody to justinlilly
  • Status changed from new to assigned

comment:10 Changed 3 years ago by anonymous

  • Has patch set

comment:11 Changed 3 years ago by ptone

  • Triage Stage changed from Accepted to Ready for checkin

applied - built docs, reads well

comment:12 Changed 3 years ago by PaulM

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

In [16874]:

Fixed #15633 -- Improved docs for post_syncdb signal.

comment:13 Changed 3 years ago by PaulM

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