Skip to content

Commit b1aa252

Browse files
committed
Array list fixes.
1 parent fa6afb3 commit b1aa252

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

stac_fastapi/core/stac_fastapi/core/models/patch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ElasticPath(BaseModel):
1717
nest: Optional[str] = None
1818
partition: Optional[str] = None
1919
key: Optional[str] = None
20-
_index: Optional[int] = None
20+
index_: Optional[int] = None
2121

2222
@model_validator(mode="before")
2323
@classmethod
@@ -28,28 +28,28 @@ def validate_model(cls, data: Any):
2828
data (Any): input data
2929
"""
3030
data["path"] = data["path"].lstrip("/").replace("/", ".")
31-
3231
data["nest"], data["partition"], data["key"] = data["path"].rpartition(".")
3332

34-
if data["key"].isdigit() or data["key"] == "-":
35-
data["_index"] = -1 if data["key"] == "-" else int(data["key"])
33+
if data["key"].lstrip("-").isdigit() or data["key"] == "-":
34+
data["index_"] = -1 if data["key"] == "-" else int(data["key"])
35+
data["path"] = f"{data['nest']}[{data['index_']}]"
3636
data["nest"], data["partition"], data["key"] = data["nest"].rpartition(".")
37-
data["path"] = f"{data['nest']}[{data['_index']}]"
3837

3938
return data
4039

40+
@computed_field # type: ignore[misc]
4141
@property
4242
def index(self) -> Union[int, str, None]:
4343
"""Compute location of path.
4444
4545
Returns:
4646
str: path location
4747
"""
48-
if self._index and self._index < 0:
48+
if self.index_ and self.index_ < 0:
4949

50-
return f"ctx._source.{self.location}.size() - {-self._index}"
50+
return f"ctx._source.{self.location}.size() - {-self.index_}"
5151

52-
return self._index
52+
return self.index_
5353

5454
@computed_field # type: ignore[misc]
5555
@property

stac_fastapi/core/stac_fastapi/core/utilities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def remove_commands(commands: List[str], path: ElasticPath) -> None:
245245
246246
"""
247247
if path.index:
248-
commands.append(f"ctx._source.{path.location}.remove('{path.index}');")
248+
commands.append(f"ctx._source.{path.location}.remove({path.index});")
249249

250250
else:
251251
commands.append(f"ctx._source.{path.nest}.remove('{path.key}');")

stac_fastapi/tests/clients/test_elasticsearch.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,10 @@ async def test_json_patch_collection_add(ctx, core_client, txn_client):
717717
collection_id = collection["id"]
718718
operations = [
719719
PatchAddReplaceTest.model_validate(
720-
{"op": "add", "path": "summaries.foo", "value": "bar"},
721-
{"op": "add", "path": "summaries.gsd.1", "value": 100},
720+
{"op": "add", "path": "/summaries/foo", "value": "bar"},
721+
),
722+
PatchAddReplaceTest.model_validate(
723+
{"op": "add", "path": "/summaries/gsd/1", "value": 100},
722724
),
723725
]
724726

@@ -742,7 +744,7 @@ async def test_json_patch_collection_replace(ctx, core_client, txn_client):
742744
collection_id = collection["id"]
743745
operations = [
744746
PatchAddReplaceTest.model_validate(
745-
{"op": "replace", "path": "summaries.gsd", "value": [100]}
747+
{"op": "replace", "path": "/summaries/gsd", "value": [100]}
746748
),
747749
]
748750

@@ -756,7 +758,7 @@ async def test_json_patch_collection_replace(ctx, core_client, txn_client):
756758
collection_id, request=MockRequest
757759
)
758760

759-
assert updated_collection["summaries"]["gsd"] == 100
761+
assert updated_collection["summaries"]["gsd"] == [100]
760762

761763

762764
@pytest.mark.asyncio
@@ -765,7 +767,7 @@ async def test_json_patch_collection_test(ctx, core_client, txn_client):
765767
collection_id = collection["id"]
766768
operations = [
767769
PatchAddReplaceTest.model_validate(
768-
{"op": "test", "path": "summaries.gsd", "value": 15}
770+
{"op": "test", "path": "/summaries/gsd", "value": [30]}
769771
),
770772
]
771773

@@ -779,7 +781,7 @@ async def test_json_patch_collection_test(ctx, core_client, txn_client):
779781
collection_id, request=MockRequest
780782
)
781783

782-
assert updated_collection["summaries"]["gsd"] == 15
784+
assert updated_collection["summaries"]["gsd"] == [30]
783785

784786

785787
@pytest.mark.asyncio
@@ -788,7 +790,7 @@ async def test_json_patch_collection_move(ctx, core_client, txn_client):
788790
collection_id = collection["id"]
789791
operations = [
790792
PatchMoveCopy.model_validate(
791-
{"op": "move", "path": "summaries.bar", "from": "summaries.gsd"}
793+
{"op": "move", "path": "/summaries/bar", "from": "/summaries/gsd"}
792794
),
793795
]
794796

@@ -802,7 +804,7 @@ async def test_json_patch_collection_move(ctx, core_client, txn_client):
802804
collection_id, request=MockRequest
803805
)
804806

805-
assert updated_collection["summaries"]["bar"] == [15]
807+
assert updated_collection["summaries"]["bar"] == [30]
806808
assert "gsd" not in updated_collection["summaries"]
807809

808810

@@ -812,7 +814,7 @@ async def test_json_patch_collection_copy(ctx, core_client, txn_client):
812814
collection_id = collection["id"]
813815
operations = [
814816
PatchMoveCopy.model_validate(
815-
{"op": "copy", "path": "summaries.foo", "from": "summaries.gsd"}
817+
{"op": "copy", "path": "/summaries/foo", "from": "/summaries/gsd"}
816818
),
817819
]
818820

@@ -836,7 +838,7 @@ async def test_json_patch_collection_remove(ctx, core_client, txn_client):
836838
collection = ctx.collection
837839
collection_id = collection["id"]
838840
operations = [
839-
PatchRemove.model_validate({"op": "remove", "path": "summaries.gsd"}),
841+
PatchRemove.model_validate({"op": "remove", "path": "/summaries/gsd"}),
840842
]
841843

842844
await txn_client.json_patch_collection(
@@ -858,7 +860,7 @@ async def test_json_patch_collection_test_wrong_value(ctx, core_client, txn_clie
858860
collection_id = collection["id"]
859861
operations = [
860862
PatchAddReplaceTest.model_validate(
861-
{"op": "test", "path": "summaries.platform", "value": "landsat-9"}
863+
{"op": "test", "path": "/summaries/platform", "value": "landsat-9"}
862864
),
863865
]
864866

@@ -879,7 +881,7 @@ async def test_json_patch_collection_replace_property_does_not_exists(
879881
collection_id = collection["id"]
880882
operations = [
881883
PatchAddReplaceTest.model_validate(
882-
{"op": "replace", "path": "summaries.foo", "value": "landsat-9"}
884+
{"op": "replace", "path": "/summaries/foo", "value": "landsat-9"}
883885
),
884886
]
885887

@@ -899,7 +901,7 @@ async def test_json_patch_collection_remove_property_does_not_exists(
899901
collection = ctx.collection
900902
collection_id = collection["id"]
901903
operations = [
902-
PatchRemove.model_validate({"op": "remove", "path": "summaries.foo"}),
904+
PatchRemove.model_validate({"op": "remove", "path": "/summaries/foo"}),
903905
]
904906

905907
with pytest.raises(HTTPException):
@@ -919,7 +921,7 @@ async def test_json_patch_collection_move_property_does_not_exists(
919921
collection_id = collection["id"]
920922
operations = [
921923
PatchMoveCopy.model_validate(
922-
{"op": "move", "path": "summaries.bar", "from": "summaries.foo"}
924+
{"op": "move", "path": "/summaries/bar", "from": "/summaries/foo"}
923925
),
924926
]
925927

@@ -940,7 +942,7 @@ async def test_json_patch_collection_copy_property_does_not_exists(
940942
collection_id = collection["id"]
941943
operations = [
942944
PatchMoveCopy.model_validate(
943-
{"op": "copy", "path": "summaries.bar", "from": "summaries.foo"}
945+
{"op": "copy", "path": "/summaries/bar", "from": "/summaries/foo"}
944946
),
945947
]
946948

0 commit comments

Comments
 (0)