Skip to content

Commit fe158f4

Browse files
committed
Move the platforms data.versions field filtering into router
This solves a problem introduced in AlmaLinux#1155
1 parent c595da3 commit fe158f4

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

alws/routers/platforms.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,20 @@ async def modify_platform(
3838
return await pl_crud.modify_platform(db, platform)
3939

4040

41-
@public_router.get('/', response_model=typing.List[platform_schema.Platform])
41+
@public_router.get('/', response_model=typing.List[platform_schema.PlatformResponse])
4242
async def get_platforms(
4343
db: AsyncSession = Depends(AsyncSessionDependency(key=get_async_db_key())),
4444
):
45-
return await pl_crud.get_platforms(db)
45+
platforms = await pl_crud.get_platforms(db)
46+
return [
47+
{
48+
**platform_schema.PlatformResponse.from_orm(
49+
platform
50+
).dict(exclude={"data"}),
51+
"data": {"versions": (platform.data or {}).get("versions", [])}
52+
}
53+
for platform in platforms
54+
]
4655

4756

4857
@router.patch(

alws/schemas/platform_schema.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,10 @@ class Platform(BaseModel):
5454
pgp_key: typing.Optional[str] = None
5555
arch_list: typing.List[str]
5656
modularity: typing.Optional[typing.Dict] = None
57-
# We're only going to take versions from 'data' column
58-
data: typing.Optional[typing.Dict[str, typing.Any]] = None
59-
60-
@root_validator(pre=True)
61-
def filter_data_to_versions_only(cls, values):
62-
if hasattr(values, 'data'):
63-
raw_data = values.data
64-
versions = raw_data.get("versions")
65-
values.data = {"versions": versions} if versions else {}
66-
return values
6757

6858
class Config:
6959
from_attributes = True
60+
61+
62+
class PlatformResponse(Platform):
63+
data: typing.Optional[typing.Dict[str, typing.Any]] = None

0 commit comments

Comments
 (0)