BertrandBordage / django-tree

Fast and easy tree structures.
BSD 3-Clause "New" or "Revised" License
88 stars 13 forks source link

Support Django 4 #9

Closed jacobjove closed 9 months ago

jacobjove commented 9 months ago

@BertrandBordage , it appears that nothing else needs to be done to make this package compatible with Django 4. I'm using it in my Django 4.2 project now with no issues.

https://docs.djangoproject.com/en/4.2/releases/4.0/#backwards-incompatible-changes-in-4-0

jacobjove commented 9 months ago

Some tests are failing, though:

test_clash_on_insert (tests.base.MultipleOrderByFieldsTest.test_clash_on_insert)
Checks that instances with exactly the same `order_by` values ... ok
test_clash_on_update (tests.base.MultipleOrderByFieldsTest.test_clash_on_update)
Checks that instances with exactly the same `order_by` values ... ok
test_rebuild (tests.base.MultipleOrderByFieldsTest.test_rebuild) ... ok
test_comparisons (tests.base.PathTest.test_comparisons) ... ok
test_cycle (tests.base.PathTest.test_cycle) ... ok
test_delete (tests.base.PathTest.test_delete) ... FAIL
test_filter_roots (tests.base.PathTest.test_filter_roots) ... ok
test_filtered_get_next_sibling (tests.base.PathTest.test_filtered_get_next_sibling) ... ERROR
test_filtered_get_prev_sibling (tests.base.PathTest.test_filtered_get_prev_sibling) ... ok
test_filtered_get_siblings (tests.base.PathTest.test_filtered_get_siblings) ... ok
test_get_ancestors (tests.base.PathTest.test_get_ancestors) ... ok
test_get_children (tests.base.PathTest.test_get_children) ... ok
test_get_descendants (tests.base.PathTest.test_get_descendants) ... ok
test_get_level (tests.base.PathTest.test_get_level) ... ok
test_get_next_sibling (tests.base.PathTest.test_get_next_sibling) ... ok
test_get_next_siblings (tests.base.PathTest.test_get_next_siblings) ... ok
test_get_prev_sibling (tests.base.PathTest.test_get_prev_sibling) ... ok
test_get_prev_siblings (tests.base.PathTest.test_get_prev_siblings) ... ok
test_get_siblings (tests.base.PathTest.test_get_siblings) ... ok
test_insert (tests.base.PathTest.test_insert) ... ok
test_is_ancestor_of (tests.base.PathTest.test_is_ancestor_of) ... ok
test_is_descendant_of (tests.base.PathTest.test_is_descendant_of) ... ok
test_is_leaf (tests.base.PathTest.test_is_leaf) ... ok
test_is_root (tests.base.PathTest.test_is_root) ... ok
test_move_root_to_next_branch (tests.base.PathTest.test_move_root_to_next_branch) ... ok
test_move_root_to_next_leaf (tests.base.PathTest.test_move_root_to_next_leaf) ... FAIL
test_move_root_to_next_root (tests.base.PathTest.test_move_root_to_next_root) ... FAIL
test_move_root_to_prev_branch (tests.base.PathTest.test_move_root_to_prev_branch) ... FAIL
test_move_root_to_prev_leaf (tests.base.PathTest.test_move_root_to_prev_leaf) ... ok
test_move_root_to_prev_root (tests.base.PathTest.test_move_root_to_prev_root) ... ok
test_new_path (tests.base.PathTest.test_new_path) ... ok
test_path_in_cursor (tests.base.PathTest.test_path_in_cursor) ... ok
test_path_on_creation (tests.base.PathTest.test_path_on_creation) ... ok
test_rebuild (tests.base.PathTest.test_rebuild) ... FAIL
test_get_descendants (tests.base.QuerySetTest.test_get_descendants) ... ok

======================================================================
ERROR: test_filtered_get_next_sibling (tests.base.PathTest.test_filtered_get_next_sibling)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 936, in test_filtered_get_next_sibling
    self.assertEqual(france.get_next_sibling(queryset=queryset).name,
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'name'

======================================================================
FAIL: test_delete (tests.base.PathTest.test_delete)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 210, in test_delete
    with self.assertNumQueries(3):
  File "/Users/jacob/code/tempo/.venv/lib/python3.12/site-packages/django/test/testcases.py", line 99, in __exit__
    self.test_case.assertEqual(
AssertionError: 5 != 3 : 5 queries executed, 3 expected
Captured queries were:
1. SELECT "tests_place"."id", "tests_place"."name", "tests_place"."parent_id", "tests_place"."path" FROM "tests_place" WHERE ("tests_place"."path")[1:3] = (ARRAY[0E-10, 0E-10,  -0.5000000000])::numeric(20, 10)[]
2. SELECT "tests_place"."id" FROM "tests_place" WHERE "tests_place"."parent_id" IN (18) ORDER BY "tests_place"."path" ASC, "tests_place"."name" ASC
3. BEGIN
4. DELETE FROM "tests_place" WHERE "tests_place"."id" IN (18)
5. COMMIT

======================================================================
FAIL: test_move_root_to_next_leaf (tests.base.PathTest.test_move_root_to_next_leaf)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 460, in test_move_root_to_next_leaf
    self.assertPlaces([
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 99, in assertPlaces
    self.assertListEqual([(p.path.value, p.name) for p in places],
AssertionError: Lists differ: [([Decimal('0E-10')], 'France'), ([Decimal('0E-10'), [572 chars]ch')] != [([Decimal('-1.0000000000')], 'Évreux'), ([Decimal('0[573 chars]ch')]

First differing element 0:
([Decimal('0E-10')], 'France')
([Decimal('-1.0000000000')], 'Évreux')

+ [([Decimal('-1.0000000000')], 'Évreux'),
- [([Decimal('0E-10')], 'France'),
? ^

+  ([Decimal('0E-10')], 'France'),
? ^

   ([Decimal('0E-10'), Decimal('0E-10')], 'Normandie'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-1.0000000000')], 'Eure'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-0.5000000000')], 'Manche'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('0E-10')], 'Seine-Maritime'),
   ([Decimal('0E-10'), Decimal('1.0000000000')], 'Poitou-Charentes'),
   ([Decimal('0E-10'), Decimal('1.0000000000'), Decimal('0E-10')], 'Vienne'),
   ([Decimal('0E-10'),
     Decimal('1.0000000000'),
     Decimal('0E-10'),
     Decimal('0E-10')],
    'Poitiers'),
-  ([Decimal('0.5000000000')], 'Évreux'),
   ([Decimal('1.0000000000')], 'Österreich')]

======================================================================
FAIL: test_move_root_to_next_root (tests.base.PathTest.test_move_root_to_next_root)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 284, in test_move_root_to_next_root
    self.assertPlaces([
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 99, in assertPlaces
    self.assertListEqual([(p.path.value, p.name) for p in places],
AssertionError: Lists differ: [([Decimal('0E-10')], 'République française'), ([Deci[547 chars]ch')] != [([Decimal('1.0000000000')], 'Österreich'), ([Decimal[603 chars]rs')]

First differing element 0:
([Decimal('0E-10')], 'République française')
([Decimal('1.0000000000')], 'Österreich')

+ [([Decimal('1.0000000000')], 'Österreich'),
- [([Decimal('0E-10')], 'République française'),
? ^            ^^^

+  ([Decimal('2.0000000000')], 'République française'),
? ^           ++ ^^^^^^^^

-  ([Decimal('0E-10'), Decimal('0E-10')], 'Normandie'),
?              ^^^

+  ([Decimal('2.0000000000'), Decimal('0E-10')], 'Normandie'),
?             ++ ^^^^^^^^

-  ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-1.0000000000')], 'Eure'),
-  ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-0.5000000000')], 'Manche'),
-  ([Decimal('0E-10'), Decimal('0E-10'), Decimal('0E-10')], 'Seine-Maritime'),
+  ([Decimal('2.0000000000'), Decimal('0E-10'), Decimal('-1.0000000000')],
+   'Eure'),
+  ([Decimal('2.0000000000'), Decimal('0E-10'), Decimal('-0.5000000000')],
+   'Manche'),
+  ([Decimal('2.0000000000'), Decimal('0E-10'), Decimal('0E-10')],
+   'Seine-Maritime'),
-  ([Decimal('0E-10'), Decimal('1.0000000000')], 'Poitou-Charentes'),
?              ^^^

+  ([Decimal('2.0000000000'), Decimal('1.0000000000')], 'Poitou-Charentes'),
?             ++ ^^^^^^^^

-  ([Decimal('0E-10'), Decimal('1.0000000000'), Decimal('0E-10')], 'Vienne'),
?              ^^^                                                -----------

+  ([Decimal('2.0000000000'), Decimal('1.0000000000'), Decimal('0E-10')],
?             ++ ^^^^^^^^

-  ([Decimal('0E-10'),
+   'Vienne'),
+  ([Decimal('2.0000000000'),
     Decimal('1.0000000000'),
     Decimal('0E-10'),
     Decimal('0E-10')],
-   'Poitiers'),
?              ^

+   'Poitiers')]
?              ^

-  ([Decimal('1.0000000000')], 'Österreich')]

======================================================================
FAIL: test_move_root_to_prev_branch (tests.base.PathTest.test_move_root_to_prev_branch)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 331, in test_move_root_to_prev_branch
    self.assertPlaces([
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 99, in assertPlaces
    self.assertListEqual([(p.path.value, p.name) for p in places],
AssertionError: Lists differ: [([De[52 chars]mal('0E-10')], 'Normandie'), ([Decimal('0E-10'[547 chars]ch')] != [([De[52 chars]mal('-1.0000000000')], 'Île-de-France'), ([Dec[548 chars]ch')]

First differing element 1:
([Decimal('0E-10'), Decimal('0E-10')], 'Normandie')
([Decimal('0E-10'), Decimal('-1.0000000000')], 'Île-de-France')

  [([Decimal('0E-10')], 'France'),
+  ([Decimal('0E-10'), Decimal('-1.0000000000')], 'Île-de-France'),
   ([Decimal('0E-10'), Decimal('0E-10')], 'Normandie'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-1.0000000000')], 'Eure'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('-0.5000000000')], 'Manche'),
   ([Decimal('0E-10'), Decimal('0E-10'), Decimal('0E-10')], 'Seine-Maritime'),
   ([Decimal('0E-10'), Decimal('1.0000000000')], 'Poitou-Charentes'),
   ([Decimal('0E-10'), Decimal('1.0000000000'), Decimal('0E-10')], 'Vienne'),
   ([Decimal('0E-10'),
     Decimal('1.0000000000'),
     Decimal('0E-10'),
     Decimal('0E-10')],
    'Poitiers'),
-  ([Decimal('0E-10'), Decimal('2.0000000000')], 'Île-de-France'),
   ([Decimal('1.0000000000')], 'Österreich')]

======================================================================
FAIL: test_rebuild (tests.base.PathTest.test_rebuild)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 1078, in test_rebuild
    self.assertPlaces([
  File "/Users/jacob/code/tempo/tempo/tree/tests/base.py", line 99, in assertPlaces
    self.assertListEqual([(p.path.value, p.name) for p in places],
AssertionError: Lists differ: [([De[170 chars])], 'Poitiers'), ([Decimal('5.0000000000')], '[143 chars]ch')] != [([De[170 chars])], 'Österreich'), ([Decimal('5.0000000000')],[143 chars]ne')]

First differing element 4:
([Decimal('4.0000000000')], 'Poitiers')
([Decimal('4.0000000000')], 'Österreich')

  [([Decimal('0E-10')], 'Eure'),
   ([Decimal('1.0000000000')], 'France'),
   ([Decimal('2.0000000000')], 'Manche'),
   ([Decimal('3.0000000000')], 'Normandie'),
+  ([Decimal('4.0000000000')], 'Österreich'),
-  ([Decimal('4.0000000000')], 'Poitiers'),
?             ^

+  ([Decimal('5.0000000000')], 'Poitiers'),
?             ^

-  ([Decimal('5.0000000000')], 'Poitou-Charentes'),
?             ^

+  ([Decimal('6.0000000000')], 'Poitou-Charentes'),
?             ^

-  ([Decimal('6.0000000000')], 'Seine-Maritime'),
?             ^

+  ([Decimal('7.0000000000')], 'Seine-Maritime'),
?             ^

-  ([Decimal('7.0000000000')], 'Vienne'),
?             ^                         ^

+  ([Decimal('8.0000000000')], 'Vienne')]
?             ^                         ^

-  ([Decimal('8.0000000000')], 'Österreich')]

----------------------------------------------------------------------
Ran 35 tests in 4.657s

FAILED (failures=5, errors=1)
Destroying test database for alias 'default' ('test_tree')...
jacobjove commented 9 months ago

^ I encounter the same errors when running the tests with or without my changes, so it looks like the tests just need to be updated. (I would appreciate confirmation of this, though.)

If that's the case, I can help update the tests at some point if you'd like.

@BertrandBordage , apologies for the large diff; my IDE is configured to autoformat code with Black on save.

merwok commented 9 months ago

FYI it is possible to call black --skip-string-normalization to avoid needless changes to quotes and multi-hundred lines PR 🙂

jacobjove commented 9 months ago

FYI it is possible to call black --skip-string-normalization to avoid needless changes to quotes and multi-hundred lines PR 🙂

Thanks. I've updated my Black extension settings in VSCode to use this argument.

jacobjove commented 9 months ago

I introduced too many unrelated changes here. I'll close this PR and open a new one.