Commit c81fa6b
Fix Item Duplicate Detection Across Datetime Indexes (#575)
**Description:**
When ENABLE_DATETIME_INDEX_FILTERING=true, items with different
datetime values are stored in different datetime-partitioned indexes.
The bulk insert methods (`bulk_async_prep_create_item`,
`bulk_sync_prep_create_item`) were using `client.exists(index=alias)`
directly, which could fail to detect existing items stored in other
datetime indexes.
Scenario that caused duplicates:
- Item product-123 with datetime: 2024-01-15 is inserted into
stac_items_collection_2024-01
- POST same product-123 with datetime: 2024-06-20 - alias check misses
it
- Item is inserted into stac_items_collection_2024-06 - duplicate
created
Solution
Extracted the duplicate check logic from `async_prep_create_item` into
reusable helper methods that properly iterate through all indexes in the
collection alias:
- `_check_item_exists_in_collection` (async)
- `_check_item_exists_in_collection_sync` (sync)
Updated all three prep methods to use these helpers:
- `async_prep_create_item`
- `bulk_async_prep_create_item`
- `bulk_sync_prep_create_item`
**PR Checklist:**
- [x] Code is formatted and linted (run `pre-commit run --all-files`)
- [x] Tests pass (run `make test`)
- [x] Documentation has been updated to reflect changes, if applicable
- [x] Changes are added to the changelog
---------
Co-authored-by: Andrzej Pijanowski <apijanowski@cloudferro.com>
Co-authored-by: Jonathan Healy <jonathan.d.healy@gmail.com>1 parent 66cffcb commit c81fa6b
File tree
8 files changed
+628
-105
lines changed- stac_fastapi
- core/stac_fastapi/core
- elasticsearch/stac_fastapi/elasticsearch
- opensearch/stac_fastapi/opensearch
- sfeos_helpers/stac_fastapi/sfeos_helpers/database
- tests
- database
- extensions
8 files changed
+628
-105
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1006 | 1006 | | |
1007 | 1007 | | |
1008 | 1008 | | |
1009 | | - | |
| 1009 | + | |
1010 | 1010 | | |
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
1014 | 1014 | | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
1015 | 1029 | | |
1016 | 1030 | | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1017 | 1034 | | |
1018 | 1035 | | |
1019 | 1036 | | |
| |||
1027 | 1044 | | |
1028 | 1045 | | |
1029 | 1046 | | |
1030 | | - | |
| 1047 | + | |
1031 | 1048 | | |
1032 | 1049 | | |
1033 | 1050 | | |
| |||
1340 | 1357 | | |
1341 | 1358 | | |
1342 | 1359 | | |
| 1360 | + | |
1343 | 1361 | | |
1344 | 1362 | | |
1345 | 1363 | | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
| 1364 | + | |
| 1365 | + | |
1350 | 1366 | | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
1351 | 1371 | | |
1352 | 1372 | | |
1353 | 1373 | | |
1354 | 1374 | | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
1355 | 1389 | | |
1356 | 1390 | | |
1357 | 1391 | | |
| |||
1364 | 1398 | | |
1365 | 1399 | | |
1366 | 1400 | | |
1367 | | - | |
| 1401 | + | |
Lines changed: 67 additions & 46 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| |||
996 | 999 | | |
997 | 1000 | | |
998 | 1001 | | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
999 | 1040 | | |
1000 | 1041 | | |
1001 | 1042 | | |
| |||
1011 | 1052 | | |
1012 | 1053 | | |
1013 | 1054 | | |
1014 | | - | |
| 1055 | + | |
1015 | 1056 | | |
1016 | 1057 | | |
1017 | 1058 | | |
1018 | | - | |
1019 | | - | |
1020 | | - | |
1021 | | - | |
1022 | | - | |
1023 | | - | |
1024 | | - | |
1025 | | - | |
1026 | | - | |
1027 | 1059 | | |
1028 | | - | |
1029 | | - | |
1030 | | - | |
1031 | | - | |
1032 | | - | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
1033 | 1064 | | |
1034 | 1065 | | |
1035 | 1066 | | |
1036 | 1067 | | |
1037 | 1068 | | |
1038 | | - | |
| 1069 | + | |
1039 | 1070 | | |
1040 | 1071 | | |
1041 | 1072 | | |
| |||
1063 | 1094 | | |
1064 | 1095 | | |
1065 | 1096 | | |
1066 | | - | |
1067 | | - | |
1068 | | - | |
1069 | | - | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
1070 | 1100 | | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | 1101 | | |
1075 | | - | |
| 1102 | + | |
1076 | 1103 | | |
1077 | 1104 | | |
1078 | | - | |
| 1105 | + | |
| 1106 | + | |
1079 | 1107 | | |
| 1108 | + | |
1080 | 1109 | | |
1081 | 1110 | | |
1082 | 1111 | | |
| |||
1085 | 1114 | | |
1086 | 1115 | | |
1087 | 1116 | | |
1088 | | - | |
| 1117 | + | |
1089 | 1118 | | |
1090 | 1119 | | |
1091 | 1120 | | |
| |||
1114 | 1143 | | |
1115 | 1144 | | |
1116 | 1145 | | |
1117 | | - | |
1118 | | - | |
1119 | | - | |
1120 | | - | |
1121 | | - | |
1122 | | - | |
1123 | | - | |
1124 | | - | |
1125 | | - | |
1126 | | - | |
1127 | | - | |
1128 | | - | |
1129 | | - | |
1130 | | - | |
1131 | | - | |
1132 | | - | |
1133 | | - | |
1134 | | - | |
1135 | | - | |
1136 | | - | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
1137 | 1158 | | |
1138 | 1159 | | |
1139 | 1160 | | |
| |||
0 commit comments