-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor db layer to access results in a consistent way (#137)
* Return row instead of dict when fetching a dataset from database This allows for attribute access instead of mapping-style access. The latter more closely resembles how we will later interact with the ORM objects. * Add simple get_dataset test case * Change more dataset functions to return Row instead of Dict To make attribute access possible, which will be more similar when we do switch over to ORM * Use one_or_none for get flow to return Row instead Since we are selecting based on the primary key we should always get at most one result. * Use Row results directly * Prefer SQLAlchemy 2.0 method names * Use newer style SQLAlchemy method instead of dictionaries and old * Change CursorMapping to Sequence[Row] for consistency
- Loading branch information
Showing
14 changed files
with
210 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
from typing import Any | ||
|
||
from database.users import User, UserGroup | ||
from schemas.datasets.openml import Visibility | ||
from sqlalchemy.engine import Row | ||
|
||
|
||
def _user_has_access( | ||
dataset: dict[str, Any], | ||
dataset: Row, | ||
user: User | None = None, | ||
) -> bool: | ||
"""Determine if `user` has the right to view `dataset`.""" | ||
is_public = dataset["visibility"] == Visibility.PUBLIC | ||
is_public = dataset.visibility == Visibility.PUBLIC | ||
return is_public or ( | ||
user is not None and (user.user_id == dataset["uploader"] or UserGroup.ADMIN in user.groups) | ||
user is not None and (user.user_id == dataset.uploader or UserGroup.ADMIN in user.groups) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.