Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Add a uniqueness constraint to the denormalised fullname model field.

If were using an earlier version of this code, you will need to change
the fullname field in the acacia_topic table to have a unique constraint
(previously, it was indexed, but not required to contain unique values,
which was an error in the design).
  • Loading branch information...
commit 009f73b46c5c05b113a034e67441eab44e3574e5 1 parent 36a0315
Malcolm Tredinnick authored
Showing with 14 additions and 2 deletions.
  1. +1 −1  acacia/
  2. +13 −1 acacia/
2  acacia/
@@ -49,7 +49,7 @@ class AbstractTopic(treebeard_mods.MP_Node):
name = models.CharField(max_length=50)
# Denormalise things a bit so that full name lookups are fast.
- full_name = models.CharField(max_length=512, db_index=True)
+ full_name = models.CharField(max_length=512, unique=True)
node_order_by = ["name"]
separator = "/"
14 acacia/
@@ -2,7 +2,7 @@
Tests for both the local treebeard overrides and the whole hierarchical topic
-from django import test
+from django import db, test
import models
@@ -150,6 +150,18 @@ def test_change_parent(self):
models.Topic.objects.get_by_full_name, "a/x/c")
+ def test_create_duplicate_entry(self):
+ """
+ Tests that an appropriate error is raised if the tree is manipulated in
+ such a way that a duplicate full name would be created.
+ """
+ target = models.Topic.objects.get_by_full_name("a")
+ node = models.Topic.objects.get_by_full_name("x")
+ # Attempting to move "x" under "a" raises an error at the database
+ # level because we already have an "a/x" node.
+ self.assertRaises(db.IntegrityError, node.move, target,
+ "sorted-child")
class TreebeardTests(BaseTestSetup, test.TestCase):
Tests for my local modification/overrides to the default treebeard
Please sign in to comment.
Something went wrong with that request. Please try again.