Store Path._directions as a JSON array
The column is of type `JSON`, but the code stored a JSON-encoded string in it; so, the data was encoded twice. A later data migration converts the existing rows.
This commit is contained in:
parent
2b1dd6af35
commit
bbd7d6a279
1 changed files with 7 additions and 12 deletions
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import functools
|
||||
import itertools
|
||||
import json
|
||||
import typing as t
|
||||
|
||||
import folium
|
||||
|
|
@ -64,7 +63,7 @@ class Path(meta.Base):
|
|||
nullable=True,
|
||||
)
|
||||
# An array of latitude-longitude pairs approximating a courier's way.
|
||||
_directions: orm.Mapped[str | None] = orm.mapped_column(
|
||||
_directions: orm.Mapped[list[list[float]] | None] = orm.mapped_column(
|
||||
"directions",
|
||||
psql.JSON,
|
||||
nullable=True,
|
||||
|
|
@ -248,7 +247,7 @@ class Path(meta.Base):
|
|||
steps.discard(self.first_address.location.lat_lng)
|
||||
steps.discard(self.second_address.location.lat_lng)
|
||||
|
||||
self._directions = json.dumps(list(steps))
|
||||
self._directions = [list(step) for step in steps]
|
||||
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
|
|
@ -271,7 +270,7 @@ class Path(meta.Base):
|
|||
msg = "_directions is not set"
|
||||
raise RuntimeError(msg)
|
||||
|
||||
points = [utils.Location(*point) for point in json.loads(self._directions)]
|
||||
points = [utils.Location(*point) for point in self._directions]
|
||||
for point in points:
|
||||
point.relate_to(self.first_address.city.southwest)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue