onespacemedia / cms

A collection of Django extensions that add content-management facilities to Django projects.
BSD 3-Clause "New" or "Revised" License
14 stars 7 forks source link

Duplicating a page has the same slug #180

Open joe-hastings opened 4 years ago

joe-hastings commented 4 years ago

I think more desired functionality would be to append something to the slug so you don't end up with two pages with the same slug where it becomes unclear which page will be viewed. We may need to append something to the title of the page to indicate its a duplicate too, when it comes to fixing this let's have a discussion on the exact desired functionality.

lewiscollard commented 4 years ago

The underlying problem here, is that this constraint is not enforced:

    class Meta:
        unique_together = (('parent', 'slug', 'country_group'),)

It looks like this should stop pages from having duplicate slugs, but it does not, because country_group can be unset, i.e. NULL. In Postgres (and all other true disciples of NULL), it is not meaningful - neither true, nor false - to ask if something is equal to NULL - and that includes NULL itself. Behold, the TRUE NATURE, the EMPTINESS, of NULL:

lewis=# SELECT 1 = 1 as wat;
 wat
-----
 t
(1 row)

lewis=# SELECT 1 = 2 as wat;
 wat
-----
 f
(1 row)

lewis=# SELECT 1 = NULL as wat;
 wat
-----

lewis=# SELECT NULL = NULL as galaxybrain;
 galaxybrain
-------------

(1 row)

ascension

So yeah, that constraint does nothing on sites that are not multilingual/multiregioned/whatever you want to call it.

Of course, we can check this in a clean method on Page instead (as None does not possess the nature of the one true NULL, or maybe it does, yet through a mirror darkly).