Skip to content

Commit

Permalink
Skymap API PUT: incorrect trigger id match bugfix (#289)
Browse files Browse the repository at this point in the history
* Don't look for existing skymap using a None trigger id, which ended up matching skymaps incorrectly.

* After finding and existing map, use it's _id to update it if needed.

* Add a unique index on dateobs + localization_name to avoid duplicates if the API code fails to find an existing map (should not happen, but it's a good failsafe anyway to have that constraint in the data model).
  • Loading branch information
Theodlz authored May 2, 2024
1 parent efdf8b5 commit e379a00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
7 changes: 7 additions & 0 deletions config.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ kowalski:
- ["candidate.dmag2mass", -1]
unique: false

skymaps:
- name: dateobs_-1_localization_name_1
fields:
- ["dateobs", -1]
- ["localization_name", 1]
unique: true

filters:
ZTF_alerts:
# default upstream aggregation pipeline stages for filtering ZTF alerts:
Expand Down
25 changes: 11 additions & 14 deletions kowalski/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3317,14 +3317,22 @@ async def put(self, request: web.Request) -> web.Response:
{
"$or": [
{"dateobs": dateobs},
{"triggerid": triggerid},
],
},
{"localization_name": skymap["localization_name"]},
]
}
if triggerid not in [None, ""]:
query["$and"][0]["$or"].append({"triggerid": triggerid})
if len(aliases) > 0:
query["$and"][0]["$or"].append({"aliases": {"$all": aliases}})
query["$and"][0]["$or"].append(
{
"$and": [
{"aliases": {"$all": aliases}},
{"aliases": {"$size": len(aliases)}},
]
}
)

existing_skymap = await request.app["mongo"][
config["database"]["collections"]["skymaps"]
Expand Down Expand Up @@ -3373,18 +3381,7 @@ async def put(self, request: web.Request) -> web.Response:
await request.app["mongo"][
config["database"]["collections"]["skymaps"]
].update_one(
{
"$and": [
{
"$or": [
{"dateobs": dateobs},
{"triggerid": triggerid},
{"aliases": {"$all": aliases}},
]
},
{"localization_name": skymap["localization_name"]},
]
},
{"_id": existing_skymap["_id"]},
{"$set": {"contours": contours}},
)
return web.json_response(
Expand Down

0 comments on commit e379a00

Please sign in to comment.