Skip to content

Commit

Permalink
Add debug logging to update_flow_run_labels
Browse files Browse the repository at this point in the history
  • Loading branch information
bunchesofdonald committed Dec 2, 2024
1 parent 7f1d04b commit d435acd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
27 changes: 9 additions & 18 deletions docs/v3/api-ref/rest-api/server/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9108,9 +9108,6 @@
"additionalProperties": {
"type": "integer"
},
"propertyNames": {
"format": "uuid"
},
"title": "Response Count Deployments By Flow Ui Flows Count Deployments Post"
}
}
Expand Down Expand Up @@ -9176,9 +9173,6 @@
}
]
},
"propertyNames": {
"format": "uuid"
},
"title": "Response Next Runs By Flow Ui Flows Next Runs Post"
}
}
Expand Down Expand Up @@ -9293,9 +9287,6 @@
"additionalProperties": {
"type": "integer"
},
"propertyNames": {
"format": "uuid"
},
"title": "Response Count Task Runs By Flow Run Ui Flow Runs Count Task Runs Post"
}
}
Expand Down Expand Up @@ -9872,7 +9863,7 @@
"type": "null"
}
],
"title": "Metadata",
"title": "Metadata ",
"description": "User-defined artifact metadata. Content must be string key and value pairs."
},
"flow_run_id": {
Expand Down Expand Up @@ -9996,7 +9987,7 @@
"type": "null"
}
],
"title": "Metadata",
"title": "Metadata ",
"description": "User-defined artifact metadata. Content must be string key and value pairs."
},
"flow_run_id": {
Expand Down Expand Up @@ -10116,7 +10107,7 @@
"type": "null"
}
],
"title": "Any",
"title": "Any ",
"description": "A list of flow run IDs to include"
}
},
Expand All @@ -10139,7 +10130,7 @@
"type": "null"
}
],
"title": "Any",
"title": "Any ",
"description": "A list of artifact keys to include"
},
"like_": {
Expand All @@ -10151,7 +10142,7 @@
"type": "null"
}
],
"title": "Like",
"title": "Like ",
"description": "A string to match artifact keys against. This can include SQL wildcard characters like `%` and `_`.",
"examples": [
"my-artifact-%"
Expand All @@ -10166,7 +10157,7 @@
"type": "null"
}
],
"title": "Exists",
"title": "Exists ",
"description": "If `true`, only include artifacts with a non-null key. If `false`, only include artifacts with a null key. Should return all rows in the ArtifactCollection table if specified."
}
},
Expand All @@ -10190,7 +10181,7 @@
"type": "null"
}
],
"title": "Any",
"title": "Any ",
"description": "A list of artifact ids to include"
}
},
Expand All @@ -10214,7 +10205,7 @@
"type": "null"
}
],
"title": "Any",
"title": "Any ",
"description": "A list of task run IDs to include"
}
},
Expand All @@ -10237,7 +10228,7 @@
"type": "null"
}
],
"title": "Any",
"title": "Any ",
"description": "A list of artifact types to include"
},
"not_any_": {
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ timeout = 90

# Error on unhandled warnings
filterwarnings =
error
# TEMPORARY until https://github.com/PrefectHQ/prefect/pull/16149 is resolved
ignore

# tornado uses deprecated `get_event_loop`
ignore::DeprecationWarning:tornado.platform.asyncio.*
Expand Down
1 change: 1 addition & 0 deletions src/prefect/server/api/flow_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ async def update_flow_run_labels(
db: PrefectDBInterface = Depends(provide_database_interface),
):
async with db.session_context() as session:
logger.info(f"Updating flow run {flow_run_id} with labels {labels}")

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
await models.flow_runs.update_flow_run_labels(
session=session, flow_run_id=flow_run_id, labels=labels
)
18 changes: 14 additions & 4 deletions src/prefect/server/models/flow_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import prefect.server.models as models
import prefect.server.schemas as schemas
from prefect.logging.loggers import get_logger
from prefect.server.database import orm_models
from prefect.server.database.dependencies import db_injector
from prefect.server.database.interface import PrefectDBInterface
Expand All @@ -47,6 +48,9 @@
PREFECT_API_MAX_FLOW_RUN_GRAPH_NODES,
)

logger = get_logger("flow_runs")


T = TypeVar("T", bound=tuple)


Expand Down Expand Up @@ -642,29 +646,35 @@ async def update_flow_run_labels(
) -> bool:
"""
Update flow run labels by patching existing labels with new values.
Args:
session: A database session
flow_run_id: the flow run id to update
labels: the new labels to patch into existing labels
Returns:
bool: whether the update was successful
"""
logger.debug(
f"Attempting to update labels for flow run {flow_run_id} with {labels}"

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
)

# First read the existing flow run to get current labels
flow_run = await read_flow_run(session, flow_run_id)
if not flow_run:
logger.warning(f"Flow run {flow_run_id} not found")

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
return False

# Merge existing labels with new labels
current_labels = flow_run.labels or {}
logger.debug(f"Current labels for {flow_run_id}: {current_labels}")

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
updated_labels = {**current_labels, **labels}
logger.debug(f"Updated labels will be: {updated_labels}")

# Update the flow run with merged labels
result = await session.execute(
sa.update(orm_models.FlowRun)
.where(orm_models.FlowRun.id == flow_run_id)
.values(labels=updated_labels)
)

return result.rowcount > 0
success = result.rowcount > 0
logger.debug(f"Update for {flow_run_id} {'succeeded' if success else 'failed'}")

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
return success

0 comments on commit d435acd

Please sign in to comment.