The primary accessor for an ORM record. Args: db_session: the database session to use when retrieving the record identifier: the identifier of the record to read, can be the id string or the UUID object for backwards compatibility actor: if specified, resu
(
cls,
db_session: "Session",
identifier: Optional[str] = None,
actor: Optional["User"] = None,
access: Optional[List[Literal["read", "write", "admin"]]] = ["read"],
access_type: AccessType = AccessType.ORGANIZATION,
**kwargs,
)
| 265 | @classmethod |
| 266 | @handle_db_timeout |
| 267 | def read( |
| 268 | cls, |
| 269 | db_session: "Session", |
| 270 | identifier: Optional[str] = None, |
| 271 | actor: Optional["User"] = None, |
| 272 | access: Optional[List[Literal["read", "write", "admin"]]] = ["read"], |
| 273 | access_type: AccessType = AccessType.ORGANIZATION, |
| 274 | **kwargs, |
| 275 | ) -> "SqlalchemyBase": |
| 276 | """The primary accessor for an ORM record. |
| 277 | Args: |
| 278 | db_session: the database session to use when retrieving the record |
| 279 | identifier: the identifier of the record to read, can be the id string or the UUID object for backwards compatibility |
| 280 | actor: if specified, results will be scoped only to records the user is able to access |
| 281 | access: if actor is specified, records will be filtered to the minimum permission level for the actor |
| 282 | kwargs: additional arguments to pass to the read, used for more complex objects |
| 283 | Returns: |
| 284 | The matching object |
| 285 | Raises: |
| 286 | NoResultFound: if the object is not found |
| 287 | """ |
| 288 | # this is ok because read_multiple will check if the |
| 289 | identifiers = [] if identifier is None else [identifier] |
| 290 | found = cls.read_multiple(db_session, identifiers, actor, access, access_type, **kwargs) |
| 291 | if len(found) == 0: |
| 292 | # for backwards compatibility. |
| 293 | conditions = [] |
| 294 | if identifier: |
| 295 | conditions.append(f"id={identifier}") |
| 296 | if actor: |
| 297 | conditions.append(f"access level in {access} for {actor}") |
| 298 | if hasattr(cls, "is_deleted"): |
| 299 | conditions.append("is_deleted=False") |
| 300 | raise NoResultFound(f"{cls.__name__} not found with {', '.join(conditions if conditions else ['no conditions'])}") |
| 301 | return found[0] |
| 302 | |
| 303 | @classmethod |
| 304 | @handle_db_timeout |
no test coverage detected