UPDATE
This commit is contained in:
+3
-11
@@ -7,7 +7,6 @@ import uuid
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.apps import apps
|
||||
from django.db import transaction
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.utils import timezone
|
||||
@@ -217,16 +216,9 @@ def reconcile_legacy_farm_plants_relation(
|
||||
farm: SensorData,
|
||||
snapshots: list[PlantCatalogSnapshot] | None = None,
|
||||
) -> None:
|
||||
snapshots = list(snapshots if snapshots is not None else get_farm_plant_snapshots(farm))
|
||||
Plant = apps.get_model("plant", "Plant")
|
||||
if Plant is None:
|
||||
return
|
||||
names = [snapshot.name for snapshot in snapshots if snapshot and snapshot.name]
|
||||
if not names:
|
||||
farm.plants.clear()
|
||||
return
|
||||
legacy_plants = list(Plant.objects.filter(name__in=names).order_by("name", "id"))
|
||||
farm.plants.set(legacy_plants)
|
||||
# AI no longer mirrors canonical plant rows locally; the legacy relation is cleared
|
||||
# so downstream services cannot accidentally read stale plant data.
|
||||
farm.plants.clear()
|
||||
|
||||
|
||||
def get_canonical_farm_record(farm_uuid: str) -> SensorData | None:
|
||||
|
||||
@@ -86,8 +86,11 @@ class FarmDetailApiTests(TestCase):
|
||||
self.assertEqual([plant.name for plant in list_runtime_plants_for_farm(farm)], ["خیار", "گوجهفرنگی"])
|
||||
self.assertEqual(get_runtime_plant_for_farm(farm).name, "خیار")
|
||||
|
||||
def test_assignment_sync_reconciles_legacy_relation_for_transition(self):
|
||||
self.assertEqual(list(self.farm.plants.values_list("name", flat=True)), ["خیار", "گوجهفرنگی"])
|
||||
def test_assignment_sync_uses_backend_snapshots_as_canonical_source(self):
|
||||
self.assertEqual(
|
||||
list(self.farm.plant_assignments.values_list("plant__name", flat=True)),
|
||||
["خیار", "گوجهفرنگی"],
|
||||
)
|
||||
|
||||
def test_runtime_plant_lookup_resolves_by_name_from_canonical_assignments(self):
|
||||
farm = get_canonical_farm_record(str(self.farm_uuid))
|
||||
|
||||
Reference in New Issue
Block a user