udata 11.1.1.dev1__py3-none-any.whl → 11.1.1.dev3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of udata might be problematic. Click here for more details.

udata/__init__.py CHANGED
@@ -4,5 +4,4 @@
4
4
  udata
5
5
  """
6
6
 
7
- __version__ = "11.1.1.dev"
8
7
  __description__ = "Open data portal"
@@ -1,5 +1,6 @@
1
1
  from blinker import Signal
2
2
  from flask import url_for
3
+ from mongoengine.errors import DoesNotExist
3
4
  from mongoengine.signals import post_delete, post_save
4
5
 
5
6
  from udata.api_fields import field
@@ -47,8 +48,12 @@ class TopicElement(Auditable, db.Document):
47
48
  @classmethod
48
49
  def post_delete(cls, sender, document, **kwargs):
49
50
  """Trigger reindex when element is deleted"""
50
- if document.topic and document.element and hasattr(document.element, "id"):
51
- reindex.delay(*as_task_param(document.element))
51
+ try:
52
+ if document.topic and document.element and hasattr(document.element, "id"):
53
+ reindex.delay(*as_task_param(document.element))
54
+ except DoesNotExist:
55
+ # Topic might have been deleted, causing dereferencing to fail
56
+ pass
52
57
  cls.on_delete.send(document)
53
58
 
54
59
 
@@ -86,6 +91,11 @@ class Topic(db.Datetimed, Auditable, Linkable, db.Document, Owned):
86
91
  on_create = Signal()
87
92
  on_update = Signal()
88
93
 
94
+ @classmethod
95
+ def post_delete(cls, sender, document, **kwargs):
96
+ """Delete associated TopicElements when a Topic is deleted"""
97
+ TopicElement.objects(topic=document).delete()
98
+
89
99
  def __str__(self):
90
100
  return self.name
91
101
 
@@ -126,4 +136,5 @@ class Topic(db.Datetimed, Auditable, Linkable, db.Document, Owned):
126
136
 
127
137
  post_save.connect(Topic.post_save, sender=Topic)
128
138
  post_save.connect(TopicElement.post_save, sender=TopicElement)
139
+ post_delete.connect(Topic.post_delete, sender=Topic)
129
140
  post_delete.connect(TopicElement.post_delete, sender=TopicElement)
@@ -0,0 +1,30 @@
1
+ """
2
+ Delete TopicElements that are not associated with an existing Topic
3
+ """
4
+
5
+ import logging
6
+
7
+ import mongoengine
8
+
9
+ from udata.core.topic.models import TopicElement
10
+
11
+ log = logging.getLogger(__name__)
12
+
13
+
14
+ def migrate(db):
15
+ log.info("Processing orphaned TopicElements...")
16
+
17
+ topic_elements = TopicElement.objects.no_cache().all()
18
+ deleted_count = 0
19
+
20
+ for element in topic_elements:
21
+ try:
22
+ # Try to access the topic - will raise DoesNotExist if topic was deleted
23
+ if element.topic:
24
+ _ = element.topic.id
25
+ except mongoengine.errors.DoesNotExist:
26
+ # Topic doesn't exist, delete the orphaned element
27
+ element.delete()
28
+ deleted_count += 1
29
+
30
+ log.info(f"Deleted {deleted_count} orphaned TopicElements")
@@ -15,7 +15,7 @@ from udata.core.topic.factories import (
15
15
  TopicFactory,
16
16
  TopicWithElementsFactory,
17
17
  )
18
- from udata.core.topic.models import Topic
18
+ from udata.core.topic.models import Topic, TopicElement
19
19
  from udata.search import reindex
20
20
  from udata.tests.helpers import assert_emit
21
21
 
@@ -142,3 +142,15 @@ class TopicModelTest:
142
142
  with pytest.raises(ValidationError):
143
143
  topic = TopicFactory()
144
144
  TopicElementFactory(topic=topic, element=DiscussionFactory())
145
+
146
+ def test_topic_deletion_deletes_associated_elements(self):
147
+ """Test that deleting a topic also deletes its associated TopicElements"""
148
+ topic = TopicWithElementsFactory()
149
+
150
+ element_ids = [elem.id for elem in topic.elements]
151
+ assert len(element_ids) > 0
152
+
153
+ topic.delete()
154
+
155
+ for element_id in element_ids:
156
+ assert TopicElement.objects(id=element_id).first() is None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: udata
3
- Version: 11.1.1.dev1
3
+ Version: 11.1.1.dev3
4
4
  Summary: Open data portal
5
5
  Author-email: Opendata Team <opendatateam@data.gouv.fr>
6
6
  Maintainer-email: Opendata Team <opendatateam@data.gouv.fr>
@@ -126,7 +126,6 @@ Requires-Dist: werkzeug==2.2.3
126
126
  Requires-Dist: wtforms[email]==3.2.1
127
127
  Requires-Dist: wtforms-json==0.3.5
128
128
  Provides-Extra: dev
129
- Requires-Dist: bumpx==0.3.10; extra == "dev"
130
129
  Requires-Dist: flask-shell-ipython==0.5.3; extra == "dev"
131
130
  Requires-Dist: invoke==2.2.0; extra == "dev"
132
131
  Requires-Dist: pip-tools==7.4.1; extra == "dev"
@@ -1,4 +1,4 @@
1
- udata/__init__.py,sha256=z-x_LDWBBmN_X2NfUodR8vC1VPSQji8MAbSrTr3qUFM,102
1
+ udata/__init__.py,sha256=U0HEYqKCLOY43O1UCVeuAb3b3SSX1pPhsJGpHJmK67k,75
2
2
  udata/api_fields.py,sha256=XI0XoM1fxO4DEzxGptOAB5SL_fJr-u58-bfQVAvzgBg,36549
3
3
  udata/app.py,sha256=gRQSi4Scqu6rj0czVsmBRkNM4wNRkBhY7y7NWbqY8UM,7249
4
4
  udata/assets.py,sha256=H5Hrc2vnKM0IFLyWfLXmJ2Kj35w1i8W1D8Cgy8_cUj4,657
@@ -242,7 +242,7 @@ udata/core/topic/api_fields.py,sha256=zMjoTSoe7-Q8F-i7Ry5EAUv-ds4Lzao3jfETZq-Vg0
242
242
  udata/core/topic/apiv2.py,sha256=WVyZDNew8m0qVFn9RLKW0SeLQHuUwWIcGAfomzua7sw,6449
243
243
  udata/core/topic/factories.py,sha256=Rhx12aTrYFZScu53IhYNP0zJKfiVZPba34ybZ7gGSwo,3010
244
244
  udata/core/topic/forms.py,sha256=OkWFo0FkSnjZ2LURoq2i2cpingFz1TrOEI3TJ7qQ8pk,3465
245
- udata/core/topic/models.py,sha256=9EFnSmlyC2mf8tJYJ2eESbjPicz--nqd6lX9tf3qIjQ,4221
245
+ udata/core/topic/models.py,sha256=kQ3EMqss5G4f6jKC528NNAoQdPxZ3I73Gv63Mt31Yvs,4656
246
246
  udata/core/topic/parsers.py,sha256=oteskLLFje-zufAYzSl1zsy-MLac2hpXhGI0S3igA1g,4560
247
247
  udata/core/topic/permissions.py,sha256=RtFPPlxuU_Bv7ip6LDO4AoPrKFnIOEs9cCMXaSSmEdk,118
248
248
  udata/core/topic/tasks.py,sha256=_OrPfuZ9rKENp4p4IkoyV-Yqp9bxI3nNxhpfKrbgl-w,357
@@ -395,6 +395,7 @@ udata/migrations/2025-07-18-compute-last-update.py,sha256=K3wSSl9oC8TRbHlvgKeekg
395
395
  udata/migrations/2025-07-18-redo-count-discussion.py,sha256=BOFTjf0zq_ahnVlYQC-d8fuoLixxyk2vP6JYJXhmvbs,941
396
396
  udata/migrations/2025-07-22-fix-duplicate-contact-points.py,sha256=ZEw2PX1E3jJiDNWLj6Y52zBAIHS-kZSLjBP6gUmA_ho,1789
397
397
  udata/migrations/2025-07-30-purge-old-harvest-dynamic-fields.py,sha256=ijeu6WvX6etOJrv0cEMCRJzj1pSetBguF-aUB1-2y_0,1017
398
+ udata/migrations/2025-10-01-delete-orphaned-topic-elements.py,sha256=Mhx5ANOihZL4botxtjvfsll-xKBtkVQBkPcSq0BJ-Ec,788
398
399
  udata/migrations/__init__.py,sha256=RBCBDaTlLjuMs_Qzwji6Z6T4r7FCGXhESKoxQbT5qAA,11221
399
400
  udata/models/__init__.py,sha256=77OriDFm4dJzQDIb-7ADKSkf9GAxkXbMHeWXoYYnTsk,1459
400
401
  udata/mongo/__init__.py,sha256=y4Rv-kq3o_kcEulcNpePLzocXPBNpx3Jd82G-VZPaMc,1421
@@ -647,7 +648,7 @@ udata/tests/test_rdf.py,sha256=XlUjRFcvTeZx1DTwwHL4pHQTcFDcAuQzaGOY_jJMDL4,4863
647
648
  udata/tests/test_routing.py,sha256=jtCZuT229WhGvJU843DtzIrdUXN5f7dym-hwz5dOFLo,10844
648
649
  udata/tests/test_storages.py,sha256=OG_PnKtPlZmmhKnbbLrvL-EMEg35wAMsTC76jVEAOLU,9602
649
650
  udata/tests/test_tags.py,sha256=y8x17-m_opa8YKjOWU60Xz6FR20FpBz61e7JJeyTwzM,3748
650
- udata/tests/test_topics.py,sha256=Z31k-9ETwfKouK-L93J7bXkCbraluhdi02E_b9is_8M,5211
651
+ udata/tests/test_topics.py,sha256=yhP-15jQ2ZVI0etfmHZfTcYEsuAeX7j-Wvg-1UiIT0E,5646
651
652
  udata/tests/test_transfer.py,sha256=_0pBwYs3T7OSZ7bO3KmQ81SjwCJyT4EVf8YYHXOkwdk,7779
652
653
  udata/tests/test_uris.py,sha256=MxafZ0SyzSNRomVpZnH1ChzWaHOi1MQiXe1gmKnBc6o,8517
653
654
  udata/tests/test_utils.py,sha256=3BGnlvw-GOE6tLHQteo-uUeYuzq4rsjePOuytFGkpOg,7967
@@ -764,9 +765,9 @@ udata/translations/pt/LC_MESSAGES/udata.mo,sha256=U0abG-nBwCIoYxRZNsc4KOLeIRSqTV
764
765
  udata/translations/pt/LC_MESSAGES/udata.po,sha256=eCG35rMzYLHXyLbsnLSexS1g0N_K-WpNHqrt_8y6I4E,48590
765
766
  udata/translations/sr/LC_MESSAGES/udata.mo,sha256=IBcCAdmcvkeK7ZeRBNRI-wJ0jzWNM0eXM5VXAc1frWI,28692
766
767
  udata/translations/sr/LC_MESSAGES/udata.po,sha256=yFxHEEB4behNwQ7JnyoYheiCKLNnMS_NV4guzgyzWcE,55332
767
- udata-11.1.1.dev1.dist-info/licenses/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
768
- udata-11.1.1.dev1.dist-info/METADATA,sha256=W2UTVkIVY8Df-s4y-Ir0obAdrXnKhv4frDnVjcu0BnU,6768
769
- udata-11.1.1.dev1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
770
- udata-11.1.1.dev1.dist-info/entry_points.txt,sha256=v2u12qO11i2lyLNIp136WmLJ-NHT-Kew3Duu8J-AXPM,614
771
- udata-11.1.1.dev1.dist-info/top_level.txt,sha256=EF6CE6YSHd_og-8LCEA4q25ALUpWVe8D0okOLdMAE3A,6
772
- udata-11.1.1.dev1.dist-info/RECORD,,
768
+ udata-11.1.1.dev3.dist-info/licenses/LICENSE,sha256=V8j_M8nAz8PvAOZQocyRDX7keai8UJ9skgmnwqETmdY,34520
769
+ udata-11.1.1.dev3.dist-info/METADATA,sha256=r1EWJq_LyZno2tzXai0fyT23th5ogI4FyVV2c5TfvRk,6723
770
+ udata-11.1.1.dev3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
771
+ udata-11.1.1.dev3.dist-info/entry_points.txt,sha256=v2u12qO11i2lyLNIp136WmLJ-NHT-Kew3Duu8J-AXPM,614
772
+ udata-11.1.1.dev3.dist-info/top_level.txt,sha256=EF6CE6YSHd_og-8LCEA4q25ALUpWVe8D0okOLdMAE3A,6
773
+ udata-11.1.1.dev3.dist-info/RECORD,,