Skip to content

prefect.server.api.variables

Routes for interacting with variable objects

get_variable_by_name_or_404(session, name) async

Returns a variable or raises 404 HTTPException if it does not exist

Source code in src/prefect/server/api/variables.py
31
32
33
34
35
36
37
38
async def get_variable_by_name_or_404(session: AsyncSession, name: str):
    """Returns a variable or raises 404 HTTPException if it does not exist"""

    variable = await models.variables.read_variable_by_name(session=session, name=name)
    if not variable:
        raise HTTPException(status_code=404, detail="Variable not found.")

    return variable

get_variable_or_404(session, variable_id) async

Returns a variable or raises 404 HTTPException if it does not exist

Source code in src/prefect/server/api/variables.py
19
20
21
22
23
24
25
26
27
28
async def get_variable_or_404(session: AsyncSession, variable_id: UUID):
    """Returns a variable or raises 404 HTTPException if it does not exist"""

    variable = await models.variables.read_variable(
        session=session, variable_id=variable_id
    )
    if not variable:
        raise HTTPException(status_code=404, detail="Variable not found.")

    return variable