Skip to content

Commit 93c35a8

Browse files
committed
fix flake8 linting errors
1 parent 3cb7d14 commit 93c35a8

5 files changed

Lines changed: 22 additions & 32 deletions

File tree

‎backend/api/context.py‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ async def get_context(
8484

8585
logger = logging.getLogger(__name__)
8686
organizations_raw = user_payload.get("organization")
87-
87+
8888
if organizations_raw is None:
8989
scope = user_payload.get("scope", "")
9090
has_org_scope = "organization" in scope.split() if scope else False
@@ -94,7 +94,7 @@ async def get_context(
9494
f"Token scope: {scope}. "
9595
f"Available claims: {sorted(user_payload.keys())}"
9696
)
97-
97+
9898
organizations = None
9999
if organizations_raw:
100100
if isinstance(organizations_raw, list):
@@ -157,7 +157,7 @@ async def get_context(
157157

158158
if db_user:
159159
try:
160-
160+
161161
await _update_user_root_locations(
162162
session,
163163
db_user,
@@ -185,17 +185,9 @@ async def _update_user_root_locations(
185185
if org_id.strip()
186186
]
187187

188-
logger = logging.getLogger(__name__)
189-
190188
root_location_ids: list[str] = []
191189

192190
if organization_ids:
193-
org_check = await session.execute(
194-
select(location_organizations.c.organization_id, location_organizations.c.location_id)
195-
.where(location_organizations.c.organization_id.in_(organization_ids))
196-
)
197-
org_entries = org_check.all()
198-
199191
result = await session.execute(
200192
select(LocationNode)
201193
.join(
@@ -239,8 +231,7 @@ async def _update_user_root_locations(
239231
),
240232
)
241233
root_location_ids.append(new_location.id)
242-
243-
234+
244235
if not root_location_ids:
245236
personal_org_title = f"{user.username}'s Organization"
246237
result = await session.execute(

‎backend/api/resolvers/location.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ async def location_roots(self, info: Info) -> list[LocationNodeType]:
2020
accessible_location_ids = await auth_service.get_user_accessible_location_ids(
2121
info.context.user, info.context
2222
)
23-
23+
2424
if not accessible_location_ids:
2525
return []
26-
26+
2727
result = await info.context.db.execute(
2828
select(models.LocationNode)
2929
.where(

‎backend/api/resolvers/patient.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ async def patients(
6868
accessible_location_ids = await auth_service.get_user_accessible_location_ids(
6969
info.context.user, info.context
7070
)
71-
71+
7272
# If user has no accessible locations, return empty list
7373
if not accessible_location_ids:
7474
return []
75-
75+
7676
query = auth_service.filter_patients_by_access(
7777
info.context.user, query, accessible_location_ids
7878
)
@@ -109,7 +109,7 @@ async def patients(
109109
if filter_cte is not None:
110110
patient_locations_filter = aliased(models.patient_locations)
111111
patient_teams_filter = aliased(models.patient_teams)
112-
112+
113113
query = (
114114
query.outerjoin(
115115
patient_locations_filter,

‎backend/api/resolvers/task.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def tasks(
8282
cte, models.LocationNode.parent_id == cte.c.id
8383
)
8484
cte = cte.union_all(children)
85-
85+
8686
if root_location_ids:
8787
invalid_ids = [lid for lid in root_location_ids if lid not in accessible_location_ids]
8888
if invalid_ids:
@@ -101,7 +101,7 @@ async def tasks(
101101
root_cte = root_cte.union_all(root_children)
102102
else:
103103
root_cte = cte
104-
104+
105105
query = (
106106
select(models.Task)
107107
.options(

‎backend/api/types/user.py‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import strawberry
44
from database import models
55
from sqlalchemy import select
6-
from sqlalchemy.orm import aliased, selectinload
76

87
if TYPE_CHECKING:
98
from api.types.location import LocationNodeType
@@ -37,31 +36,31 @@ async def tasks(
3736
info,
3837
) -> list[Annotated["TaskType", strawberry.lazy("api.types.task")]]:
3938
from api.services.authorization import AuthorizationService
40-
39+
4140
auth_service = AuthorizationService(info.context.db)
4241
accessible_location_ids = await auth_service.get_user_accessible_location_ids(
4342
info.context.user, info.context
4443
)
45-
44+
4645
if not accessible_location_ids:
4746
return []
48-
47+
4948
from sqlalchemy.orm import aliased
5049
patient_locations = aliased(models.patient_locations)
5150
patient_teams = aliased(models.patient_teams)
52-
51+
5352
from sqlalchemy import select
5453
cte = (
5554
select(models.LocationNode.id)
5655
.where(models.LocationNode.id.in_(accessible_location_ids))
5756
.cte(name="accessible_locations", recursive=True)
5857
)
59-
58+
6059
children = select(models.LocationNode.id).join(
6160
cte, models.LocationNode.parent_id == cte.c.id
6261
)
6362
cte = cte.union_all(children)
64-
63+
6564
query = (
6665
select(models.Task)
6766
.join(models.Patient, models.Task.patient_id == models.Patient.id)
@@ -91,7 +90,7 @@ async def tasks(
9190
)
9291
.distinct()
9392
)
94-
93+
9594
result = await info.context.db.execute(query)
9695
return result.scalars().all()
9796

@@ -102,7 +101,7 @@ async def root_locations(
102101
) -> list[Annotated["LocationNodeType", strawberry.lazy("api.types.location")]]:
103102
import logging
104103
logger = logging.getLogger(__name__)
105-
104+
106105
# First check what's in user_root_locations table
107106
user_root_check = await info.context.db.execute(
108107
select(models.user_root_locations.c.location_id).where(
@@ -111,7 +110,7 @@ async def root_locations(
111110
)
112111
user_root_location_ids = [row[0] for row in user_root_check.all()]
113112
logger.info(f"User {self.id} has {len(user_root_location_ids)} entries in user_root_locations: {user_root_location_ids}")
114-
113+
115114
result = await info.context.db.execute(
116115
select(models.LocationNode)
117116
.join(
@@ -123,7 +122,7 @@ async def root_locations(
123122
)
124123
locations = result.scalars().all()
125124
logger.info(f"User {self.id} root_locations query returned {len(locations)} locations: {[loc.id for loc in locations]}")
126-
125+
127126
# If we have user_root_locations entries but no locations returned, check if locations exist
128127
if user_root_location_ids and not locations:
129128
location_check = await info.context.db.execute(
@@ -137,5 +136,5 @@ async def root_locations(
137136
f"Checking if locations exist: {[loc.id for loc in existing_locations]} "
138137
f"with parent_ids: {[loc.parent_id for loc in existing_locations]}"
139138
)
140-
139+
141140
return locations

0 commit comments

Comments
 (0)