Skip to content

Fixes the bug related to the geometries of duplicated interventions - #5645

Open
PartyNell wants to merge 4 commits into
masterfrom
intervention_duplication
Open

Fixes the bug related to the geometries of duplicated interventions#5645
PartyNell wants to merge 4 commits into
masterfrom
intervention_duplication

Conversation

@PartyNell

Copy link
Copy Markdown
Contributor

Description

When duplicating an intervention based on a path, the topology representing the geometry was not duplicated. As a result, both interventions shared the same geometry.

Related Issue

Checklist

  • I have followed the guidelines in our Contributing document
  • My code respects the Definition of done available in the Development section of the documentation
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes
  • I added an entry in the changelog file
  • My commits are all using prefix convention (emoji + tag name) and references associated issues
  • I added a label to the PR corresponding to the perimeter of my contribution
  • The title of my PR mentionned the issue associated

AI requirements

Skip the checkboxes below 👇 If you didn't use AI for your contribution

  • I used AI assistance to produce part or all of this contribution
  • I have read, reviewed, understood and can explain the code I am submitting
  • I can explain and discuss my work to a maintainer
  • I pasted the prompt used and mentioned the model used below

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.54%. Comparing base (e43b731) to head (f1bd310).
⚠️ Report is 6 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5645   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         274      274           
  Lines       23025    23034    +9     
=======================================
+ Hits        22690    22699    +9     
  Misses        335      335           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cypress

cypress Bot commented Aug 14, 2026

Copy link
Copy Markdown

Geotrek-admin    Run #17643

Run Properties:  status check passed Passed #17643  •  git commit 3a45bfe697 ℹ️: Merge f1bd310d14eb3406f8a9319d7bf4636aea5a844c into cc3e312d7ba4171ac63a2af9a688...
Project Geotrek-admin
Branch Review refs/pull/5645/merge
Run status status check passed Passed #17643
Run duration 02m 09s
Commit git commit 3a45bfe697 ℹ️: Merge f1bd310d14eb3406f8a9319d7bf4636aea5a844c into cc3e312d7ba4171ac63a2af9a688...
Committer Nell Party
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 22
View all changes introduced in this branch ↗︎

Comment thread docs/changelog.rst

**Bug fixes**

* Fix geometry of duplicated intervention

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Fix geometry of duplicated intervention
* Fix intervention duplication to also duplicate its target when linked to its own topology instead of another object (e.g. signage, etc) (refs #3845)

interv = InterventionFactory.create(target=None)
self.assertIn("-", interv.target_csv_display)

def test_duplication_with_topology_target(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ajouterais bien une docstring pour expliquer ce qu'on teste, avec pourquoi pas un lien vers l'issue

def duplicate(self, **kwargs):
clone = super().duplicate(**kwargs)
if clone.target_type == ContentType.objects.get_for_model(Topology):
# if the target is a topology create a new one with the same information

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# if the target is a topology create a new one with the same information
# if the target is a topology instead of another object (e.g. signage, etc), create a new one with the same information

interv = InterventionFactory.create(target=None)
self.assertIn("-", interv.target_csv_display)

def test_duplication_with_topology_target(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ajouter un test pour vérifier que dans le cas où l'intervention est liée à un autre objet, cet objet n'est pas dupliqué / une nouvelle topologie n'est pas créée (en gros il faut tester le cas où on ne rentre pas dans le if)

topology_copy = intervention_copy.target
self.assertEqual(topology_copy.geom, topology.geom)
self.assertEqual(topology_copy.offset, topology.offset)
self.assertEqual(topology_copy.kind, "INTERVENTION")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vérifier que topology_copy et topology n'aient pas le même pk

Comment on lines +353 to +355
Intervention.duplicate(intervention)
self.assertEqual(Intervention.objects.count(), 2)
intervention_copy = Intervention.objects.get(name="intervention test (copy)")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Intervention.duplicate(intervention)
self.assertEqual(Intervention.objects.count(), 2)
intervention_copy = Intervention.objects.get(name="intervention test (copy)")
intervention_copy = Intervention.duplicate(intervention)
self.assertEqual(Intervention.objects.count(), 2)

2 avantages :

  • on teste la valeur de retour de la méthode
  • fonctionnera toujours si on change le nom généré par défaut lors d'une duplication (pas géré par la méthode qu'on teste ici)

Comment on lines 171 to 180
fields_name_different = [
"id",
"uuid",
"date_insert",
"date_update",
"name",
"name_en",
"target_id",
"target",
]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'était comme ça de base, mais en profiter pour sortir cette définition liste de dans la boucle for, et la mettre juste au dessus ? pas besoin de la redéfinir à chaque tour de boucle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants