Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up PrefectDBInterface, use the models consistently #16392

Merged

Conversation

mjpieters
Copy link
Contributor

@mjpieters mjpieters commented Dec 15, 2024

Related: #16292

Copy link

codspeed-hq bot commented Dec 15, 2024

CodSpeed Performance Report

Merging #16392 will not alter performance

Comparing mjpieters:cleanup_server_database_interfaces (1217948) with main (a0248c7)

Summary

✅ 3 untouched benchmarks

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 6 times, most recently from 5a477e6 to bef28bd Compare December 15, 2024 18:07
@github-actions github-actions bot added docs ui-replatform Related to the React UI rewrite labels Dec 15, 2024
@aaazzam aaazzam removed docs ui-replatform Related to the React UI rewrite labels Dec 15, 2024
@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch from bef28bd to dbc0c40 Compare December 15, 2024 20:24
@github-actions github-actions bot added docs ui-replatform Related to the React UI rewrite labels Dec 15, 2024
@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch from dbc0c40 to 537a048 Compare December 15, 2024 21:23
@mjpieters mjpieters marked this pull request as ready for review December 15, 2024 21:29
@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 2 times, most recently from 35a7a13 to 382d5d9 Compare December 16, 2024 10:48
@mjpieters
Copy link
Contributor Author

Type completeness increased by 1.83%

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 3 times, most recently from bc9fe02 to 17f8d7f Compare December 16, 2024 20:58
Copy link
Member

@desertaxle desertaxle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I want to make sure @zzstoatzz also gets a chance to look to ensure I'm not missing anything.

Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i haven't looked deeply enough yet to know which of the changes caused this, but i am seeing 500s from the graph v2 endpoint in the UI (flow run timeline) and the flow run timeline does not render for flow runs

  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/server/utilities/database.py", line 128, in process_bind_param
    raise ValueError("Timestamps must have a timezone.")
sqlalchemy.exc.StatementError: (builtins.ValueError) Timestamps must have a timezone.
[SQL: WITH edges AS
(SELECT CASE WHEN (flow_run.id IS NOT NULL) THEN :param_1 ELSE :param_2 END AS kind, coalesce(flow_run.id, task_run.id) AS id, coalesce(flow.name || :name_1 || flow_run.name, task_run.name) AS label, coalesce(flow_run.state_type, task_run.state_type) AS state_type, coalesce(flow_run.start_time, flow_run.expected_start_time, task_run.start_time, task_run.expected_start_time) AS start_time, coalesce(flow_run.end_time, task_run.end_time, CASE WHEN (task_run.state_type = :state_type_1) THEN task_run.expected_start_time ELSE NULL END) AS end_time, JSON_EXTRACT(argument.value, :value_1) AS parent, input."key" = :key_1 AS has_encapsulating_task
FROM task_run LEFT OUTER JOIN json_each(task_run.task_inputs) AS input ON 1 = 1 LEFT OUTER JOIN json_each(input.value) AS argument ON 1 = 1 LEFT OUTER JOIN flow_run ON flow_run.parent_task_run_id = task_run.id LEFT OUTER JOIN flow ON flow.id = flow_run.flow_id
WHERE task_run.flow_run_id = :flow_run_id AND task_run.state_type != :state_type_2 AND coalesce(flow_run.start_time, flow_run.expected_start_time, task_run.start_time, task_run.expected_start_time) IS NOT NULL ORDER BY coalesce(flow_run.id, task_run.id)),
with_parents AS
(SELECT children.id AS id, json_group_array(parents.id) AS parent_ids
FROM edges AS children JOIN edges AS parents ON parents.id = children.parent
WHERE children.has_encapsulating_task IS NOT 1 GROUP BY children.id),
with_children AS
(SELECT parents.id AS id, json_group_array(children.id) AS child_ids
FROM edges AS parents JOIN edges AS children ON children.parent = parents.id
WHERE children.has_encapsulating_task IS NOT 1 GROUP BY parents.id),
with_encapsulating AS
(SELECT children.id AS id, json_group_array(parents.id) AS encapsulating_ids
FROM edges AS children JOIN edges AS parents ON parents.id = children.parent
WHERE children.has_encapsulating_task IS 1 GROUP BY children.id),
nodes AS
(SELECT DISTINCT edges.kind AS kind, edges.id AS id, edges.label AS label, edges.state_type AS state_type, edges.start_time AS start_time, edges.end_time AS end_time, with_parents.parent_ids AS parent_ids, with_children.child_ids AS child_ids, with_encapsulating.encapsulating_ids AS encapsulating_ids
FROM edges LEFT OUTER JOIN with_parents ON with_parents.id = edges.id LEFT OUTER JOIN with_children ON with_children.id = edges.id LEFT OUTER JOIN with_encapsulating ON with_encapsulating.id = edges.id)
 SELECT nodes.kind, nodes.id, nodes.label, nodes.state_type, nodes.start_time, nodes.end_time, nodes.parent_ids AS parent_ids, nodes.child_ids AS child_ids, nodes.encapsulating_ids AS encapsulating_ids
FROM nodes
WHERE nodes.end_time IS NULL OR nodes.end_time >= :since ORDER BY nodes.start_time, nodes.end_time
 LIMIT :max_nodes OFFSET :param_3]
[parameters: [{'flow_run_id': UUID('a51a080f-c046-464f-bc7b-ccb0289ea7b8'), 'since': datetime.datetime(1, 1, 1, 0, 0), 'max_nodes': 10001}]]

at a glance, looks like some timestamp issue

  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/server/utilities/database.py", line 128, in process_bind_param
    raise ValueError("Timestamps must have a timezone.")
sqlalchemy.exc.StatementError: (builtins.ValueError) Timestamps must have a timezone.

i do not observe this on main

@mjpieters
Copy link
Contributor Author

mjpieters commented Dec 17, 2024

i haven't looked deeply enough yet to know which of the changes caused this, but i am seeing 500s from the graph v2 endpoint in the UI (flow run timeline) and the flow run timeline does not render for flow runs

at a glance, looks like some timestamp issue

  File "/Users/nate/github.com/prefecthq/prefect/src/prefect/server/utilities/database.py", line 128, in process_bind_param
    raise ValueError("Timestamps must have a timezone.")
sqlalchemy.exc.StatementError: (builtins.ValueError) Timestamps must have a timezone.

i do not observe this on main

I'm having trouble reproducing this; I tried running a flow with my local server and looked at the Runs section for the flow, and these all work.

This was using PostgreSQL however, and your included SQL query suggests this was with SQLite. However, both codepaths use the same bindparam() configuration.

@zzstoatzz
Copy link
Collaborator

zzstoatzz commented Dec 17, 2024

thanks for the update @mjpieters!

I've updated the /flow_runs/{id:uuid}/graph-v2 endpoint to take the since query parameter as a pendulum.DateTime instance instead of datetime.datetime; this was probably a source of bugs as that's a naive datetime and not one with a timezone, anyway. That fixed the issue.

this makes sense to me. looks like we have a couple remaining dt serialization issues, but otherwise this is looking good to me - thanks so much for all the improvements!

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 3 times, most recently from c8942ac to 8b4aaf0 Compare December 17, 2024 19:18
@mjpieters
Copy link
Contributor Author

mjpieters commented Dec 17, 2024

this makes sense to me. looks like we have a couple remaining dt serialization issues, but otherwise this is looking good to me - thanks so much for all the improvements!

@zzstoatzz You didn't mark the PR as approved (it still says that there are required changes), but you didn't make any comments about what should be changed. Was that an oversight somewhere or is there something I still need to fix?

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 4 times, most recently from f00300d to d90d102 Compare December 18, 2024 18:37
@mjpieters
Copy link
Contributor Author

The 3 test failures here are due to #16440

Copy link
Collaborator

@zzstoatzz zzstoatzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @mjpieters - apologies for the slight delay in turn around

You didn't mark the PR as approved (it still says that there are required changes), but you didn't make any comments about what should be changed.

at the time of commenting the following:

looks like we have a couple remaining dt serialization issues

I was seeing test failures related to datetime serialization that look to now be resolved, so I intentionally did not approve at that time

your current failures should be unrelated and resolved by #16433

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 2 times, most recently from 7f1a833 to 27b7007 Compare December 18, 2024 21:17
@mjpieters
Copy link
Contributor Author

your current failures should be unrelated and resolved by #16433

Yup, I had even filed #16440 before I noticed that there was already an MR out fixing it. :-)

@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 7 times, most recently from 79de108 to db65ad9 Compare December 19, 2024 21:08
@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch 2 times, most recently from 064e604 to 1a962b6 Compare December 19, 2024 23:56
@mjpieters mjpieters force-pushed the cleanup_server_database_interfaces branch from 1a962b6 to 1217948 Compare December 20, 2024 00:43
@desertaxle desertaxle merged commit 3d9e9db into PrefectHQ:main Dec 20, 2024
39 checks passed
@mjpieters mjpieters deleted the cleanup_server_database_interfaces branch December 20, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs ui-replatform Related to the React UI rewrite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants