Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#31629 closed Bug (invalid)

Sites framework post_migrate signal overwrites user created site.

Reported by: Tom Carrick Owned by: nobody
Component: contrib.sites Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There is some advice in the documentation:

django.contrib.sites registers a post_migrate signal handler which creates a default site named example.com with the domain example.com. This site will also be created after Django creates the test database. To set the correct name and domain for your project, you can use a data migration.

This advice can be quite contradictory. It only works if you've already run migrations once before adding the data migration, so it doesn't work for new deployments. This is because creating the default site will overwrite what is currently there, as the post_migrate signal runs after the user's data migration.

I think that create_default_site() shouldn't overwrite any data, it should only create the site if the table is empty, or at least only if the id isn't already in use.

If the current behaviour is intentional for some reason, I think we should at least remove the advice to create a data migration from the docs.

Change History (2)

comment:1 by Carlton Gibson, 4 years ago

Resolution: invalid
Status: newclosed

Hi Tom.

Can I ask you to clarify here? AFAICS, the site creation is already behind a `not exists` conditional — so if you do create a data migration the create_default_site() is a noop.

Maybe I've misunderstood though...
Thanks.

comment:2 by Tom Carrick, 4 years ago

You are right. Looking again, my data migration was wrong: it was assuming the site was already there.

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