From c18f26a21431547ff2b5b4f44c31cc3888cbfebb Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Fri, 10 Jan 2025 11:52:26 -0500 Subject: [PATCH 1/3] fix missing facility specification * default of nsls2 results in PASS API exception: httpx.HTTPStatusError: Client error '400 Bad Request' for url 'https://passservices.bnl.gov/....../NSLS-II/300047/null' --- src/nsls2api/services/sync_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nsls2api/services/sync_service.py b/src/nsls2api/services/sync_service.py index 08180128..cd878dbe 100644 --- a/src/nsls2api/services/sync_service.py +++ b/src/nsls2api/services/sync_service.py @@ -132,7 +132,7 @@ async def worker_synchronize_cycles_from_pass( ) # Now let's update the list of proposals for this cycle - proposals_list = await pass_service.get_proposals_allocated_by_cycle(cycle.name) + proposals_list = await pass_service.get_proposals_allocated_by_cycle(cycle.name, cycle.facility) for proposal in proposals_list: await updated_cycle.update( AddToSet({Cycle.proposals: str(proposal.Proposal_ID)}) From d94f1e902063b058201ca83680f5630d7c3c0e48 Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Fri, 10 Jan 2025 12:05:29 -0500 Subject: [PATCH 2/3] make facility name kwarg, use facility name * use facility_name instead of cycle.facility because this is of type `FacilityName` --- src/nsls2api/services/sync_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nsls2api/services/sync_service.py b/src/nsls2api/services/sync_service.py index cd878dbe..8a0af20a 100644 --- a/src/nsls2api/services/sync_service.py +++ b/src/nsls2api/services/sync_service.py @@ -132,7 +132,7 @@ async def worker_synchronize_cycles_from_pass( ) # Now let's update the list of proposals for this cycle - proposals_list = await pass_service.get_proposals_allocated_by_cycle(cycle.name, cycle.facility) + proposals_list = await pass_service.get_proposals_allocated_by_cycle(cycle.name, facility=facility_name) for proposal in proposals_list: await updated_cycle.update( AddToSet({Cycle.proposals: str(proposal.Proposal_ID)}) From 8b068ceb4a83ec0b69f787c3ec0f971511178ee2 Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Fri, 10 Jan 2025 12:54:49 -0500 Subject: [PATCH 3/3] fix Cycle.find_one() to include facility in query * ensure that the appropriate cycle is found, because the cycle name may be the same between multiple facilities --- src/nsls2api/services/pass_service.py | 2 +- src/nsls2api/services/sync_service.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/nsls2api/services/pass_service.py b/src/nsls2api/services/pass_service.py index 4bc55a91..af07555f 100644 --- a/src/nsls2api/services/pass_service.py +++ b/src/nsls2api/services/pass_service.py @@ -199,7 +199,7 @@ async def get_proposals_allocated_by_cycle( logger.error(error_message) raise PassException(error_message) - cycle = await Cycle.find_one(Cycle.name == cycle_name) + cycle = await Cycle.find_one(Cycle.name == cycle_name, Cycle.facility == facility) if not cycle: error_message: str = f"Could not find a cycle with the name {cycle_name}." logger.error(error_message) diff --git a/src/nsls2api/services/sync_service.py b/src/nsls2api/services/sync_service.py index 8a0af20a..46f0ce2d 100644 --- a/src/nsls2api/services/sync_service.py +++ b/src/nsls2api/services/sync_service.py @@ -114,7 +114,7 @@ async def worker_synchronize_cycles_from_pass( pass_id=str(pass_cycle.ID), ) - updated_cycle = await Cycle.find_one(Cycle.name == pass_cycle.Name).upsert( + updated_cycle = await Cycle.find_one(Cycle.name == pass_cycle.Name, Cycle.facility == facility.facility_name).upsert( Set( { Cycle.accepting_proposals: cycle.accepting_proposals,