Skip to content

sqlalchemy v2 - #150

Open
zmc wants to merge 20 commits into
mainfrom
update-deps
Open

zmc wants to merge 20 commits into
mainfrom
update-deps

Conversation

@zmc

@zmc zmc commented Jul 7, 2026

Copy link
Copy Markdown
Member

No description provided.

@zmc
zmc force-pushed the update-deps branch 5 times, most recently from a501318 to b4451d2 Compare July 13, 2026 21:23
@zmc
zmc marked this pull request as ready for review July 13, 2026 21:26
@zmc
zmc requested review from VallariAg and amathuria July 14, 2026 16:27
@amathuria

Copy link
Copy Markdown
Contributor

Working on reviewing this ASAP

@djgalloway

Copy link
Copy Markdown
Contributor

I didn't want to interfere with your branch so I made a new one, rebased on main, and fixed a few regressions. #153

Tested end to end on an exact copy of today's paddles database.

zmc and others added 18 commits November 18, 2026 21:22
Also:
- update pecan
- update psycopg to v3
- drop statsd

Signed-off-by: Zack Cerza <[email protected]>
Before:
* Used global thread-scoped sessions
* Sessions could leak between requests causing incorrect updates
* Tests were difficult to get right

After:
* Request-scoped sessions that are isolated from each other
* Lifecycle managed in one place
* Guaranteed cleanup on error
* Tests are more terse and easily understood
* Pytest fixtures which make tests composable and more maintainable
* Tests do not persist any state to the database
* Eaasy to invoke integration tests

Signed-off-by: Zack Cerza <[email protected]>
This endpoint's logic was a little strange and was also implemented as requiring
a POST request. Simplify it and correct its behavior.
Also fix a test bug.

Signed-off-by: Zack Cerza <[email protected]>
* Update python and actions versions
* We don't use travis or nose

Signed-off-by: Zack Cerza <[email protected]>
This lets us simplify error handling in controllers, and to avoid ever returning
HTML inadvertently

Signed-off-by: Zack Cerza <[email protected]>
Run the full test suite with a live paddles server backed by an ephemeral
PostgreSQL service container so race and HTTP integration tests execute in CI.

Signed-off-by: Zack Cerza <[email protected]>
This fixes failures that I only saw in GitHub Actions

Signed-off-by: Zack Cerza <[email protected]>
Every timestamp column is 'timestamp without time zone' and has always
held naive UTC. Writing tz-aware values made stored values depend on the
server's TimeZone and made JSON output differ between freshly-set and
reloaded objects. updated_cb normalizes to naive UTC before comparing.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
…nown keys

- Job.updated (and, via updated_cb, Run.updated) advances on every
  update, including a status-less PUT, which teuthology's supervisor
  watchdog sends purely to bump it. Stale-lock detection and pulpito
  runtimes read it.
- success is stored alongside status; teuthology's set_status() always
  sends both.
- Only real columns are settable. Unknown or protected keys (id,
  posted, ...) are ignored instead of raising.
- __init__ goes through update() for targets and updated, so the
  separate init listener is gone.

Adds paddles/tests/controllers/test_teuthology_flows.py.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
- Catch ValueError from Job()/Job.update() in the job controllers and
  turn it into /errors/invalid/.
- validate_status: %-formatting a tuple raised TypeError instead of
  the intended ValueError.
- timestamp_cb passes None and datetime values through instead of
  handing them to strptime.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
Check for an existing (run, job_id) before inserting and report "job with
job_id N already exists", which teuthology needs to see before it falls
back to a PUT. A lost race with a concurrent create (IntegrityError) gets
the same message instead of quietly returning the other request's job.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
A job dict round-tripped from paddles' own GET carries "queue": null,
which was rejected as having both job_id and queue. When paddles
generates job ids itself, non-numeric existing ids no longer break int().

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
The hybrid property made /runs/status/<status>/ (pulpito's running-runs
filter) run correlated subqueries over every job of every run: ~25s on
a copy of the production database. Run.status is a real, indexed column
again, recomputed via Run.set_status() whenever a job is updated and via
Run.refresh_status() after a job is deleted. Run.started is set when the
run first becomes running; this replaces status_cb.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
teuthology creates a job without targets and sends them in a PUT once it
has locked nodes. before_flush only looked at new jobs, so job_nodes was
never populated, leaving /nodes/<name>/jobs/, node job_stats, the
reimage-failure detector and testnode-monitor with no data for new
jobs. Also look at dirty jobs whose targets changed.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
/runs/branch/, /runs/machine_type/, etc. returned one entry per run and
500ed whenever a single value was NULL (sorted() can't compare None).

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
The SQLAlchemy 2 port removed models.start()/commit() and the Query API,
which every pecan command still used. Add a small SessionCommand base
that opens a plain session from paddles.db, and port dedupe, delete,
expire_jobs, node_jobs, node_stats, queue_stats, reparse, set_status and
set_targets onto it. set_status gains --all to recompute every run's
stored status.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
It imports nodes from a lock server that no longer exists, and would
need porting off the removed models.start()/Query API like the other
commands.

Found by testing the SQLAlchemy 2 port against a copy of the production
database (#153).

Assisted-by: Claude Fable 5.1
Assisted-by: Claude Opus 5.5
@zmc

zmc commented Nov 19, 2026

Copy link
Copy Markdown
Member Author

@djgalloway I've folded your fixes from #153 into this PR, so you don't need to restructure anything on your end.

  • Your production-based fixes are now separate commits on top, authored by you but with messages written by Opus 5.5 crediting SQLAlchemy v2: production fixes on top of #150 #153. They do not have Signed-off-by trailers as those would be for you to add; would you want to add them and re-push this branch?
  • The fixes for issues in my commits are squashed into the commits that introduced them.
  • The branch is rebased onto main, with the migration chained after package_source. The Node model: Don't lose locks when lock_many hits a DB error #154 lock_many fix is carried over the same way you resolved it.
  • I left out the hardcoded CORS/Sentry hooks for now. I'd rather put them back through config.

Thanks for testing this against a copy of production. It caught a lot. Once you've had a look, I think #153 can be closed in favor of this one.

@djgalloway

Copy link
Copy Markdown
Contributor

@djgalloway I've folded your fixes from #153 into this PR, so you don't need to restructure anything on your end.

* Your production-based fixes are now separate commits on top, authored by you but with messages written by Opus 5.5 crediting [SQLAlchemy v2: production fixes on top of #150 #153](https://github.com/ceph/paddles/pull/153). They _do not have_ Signed-off-by trailers as those would be for you to add; would you want to add them and re-push this branch?

* The fixes for issues in my commits are squashed into the commits that introduced them.

* The branch is rebased onto main, with the migration chained after package_source. The [Node model: Don't lose locks when lock_many hits a DB error #154](https://github.com/ceph/paddles/pull/154) lock_many fix is carried over the same way you resolved it.

* I left out the hardcoded CORS/Sentry hooks for now. I'd rather put them back through config.

Thanks for testing this against a copy of production. It caught a lot. Once you've had a look, I think #153 can be closed in favor of this one.

If you've already folded and squashed the fixes for your commits into this PR, I am not particularly concerned with attribution. If you're happy with unsigned commits in paddles.git, so am I.

@zmc

zmc commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

We have a number of commits that lack a DCO in this repo, and DCO in combination with Assisted-by is of debatable significance. I'm fine either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants