Skip to content

Support ordering circuits by target_simulator#640

Merged
pgetta merged 1 commit into
mainfrom
feat/order-circuits-by-target-simulator
Jun 26, 2026
Merged

Support ordering circuits by target_simulator#640
pgetta merged 1 commit into
mainfrom
feat/order-circuits-by-target-simulator

Conversation

@pgetta

@pgetta pgetta commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Enables ordering the GET /circuit list endpoint by target_simulator, which previously returned a 422 because the field was not whitelisted for sorting.

Changes

  • app/filters/circuit.py — add target_simulator to CircuitFilter.Constants.ordering_model_fields, so order_by=target_simulator / order_by=-target_simulator are accepted. (target_simulator was already a supported filter; this adds sorting.)
  • app/db/types.py — reorder the TargetSimulator enum into alphabetical order (Brian2, CORENEURON, LearningEngine, NEURON). Native Postgres enums sort by definition order, so this makes the ascending sort intuitive and lexicographic.
  • alembic/versions/…9e36650e03a9… — migration syncing the DB enum to the new order via op.sync_enum_values, with a symmetric downgrade. The circuit.target_simulator column and its 'NEURON' server default are preserved.
  • tests/test_circuit.py — circuits had no ordering test; add test_ordering that exercises every sortable field (asc/desc, count-preserving) and spot-checks target_simulator order against the enum's definition order. Also varies target_simulator across the models fixture and updates the affected filter assertion.
  • scripts/export/build_database_archive.sh — refreshed head revision (auto-updated by make migration).

Deployment note

sync_enum_values can't reorder a Postgres enum in place — it recreates the type and runs ALTER TABLE circuit ALTER COLUMN … TYPE … USING …, which takes an ACCESS EXCLUSIVE lock and rewrites the column for the duration. No data is at risk (no values removed/renamed), but it briefly blocks on a large circuit table.

Testing

  • make lint — ruff + pyright clean.
  • PYTEST_ADDOPTS="-k test_circuit" make test-local — 52 passed, including the new test_ordering and the updated test_filtering, against a DB with the new migration applied.

Comment thread app/db/types.py
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
pytest 97.75% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
app/db/types.py 99.55% <100.00%> (ø)
app/filters/circuit.py 100.00% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pgetta pgetta requested a review from GianlucaFicarelli June 24, 2026 09:05
@pgetta

pgetta commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@eleftherioszisis eleftherioszisis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@pgetta pgetta changed the title feat: support ordering circuits by target_simulator Support ordering circuits by target_simulator Jun 24, 2026
@pgetta

pgetta commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Thank you Eleftherios.

Comment thread app/filters/circuit.py
Add target_simulator to CircuitFilter ordering_model_fields so
GET /circuit accepts order_by=target_simulator (ascending/descending)
instead of returning a 422.

Reorder the TargetSimulator enum to alphabetical order so the native
Postgres enum sort order is intuitive, with a migration to sync the DB
enum values. Add a circuit ordering test (the suite previously had none)
that exercises every sortable field and spot-checks target_simulator
order via the enum's definition order.
@pgetta pgetta force-pushed the feat/order-circuits-by-target-simulator branch from f44e576 to 98f5801 Compare June 26, 2026 08:25
@pgetta

pgetta commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Had to rebase and force push due to a conflicting migrations. Could you please re-approve?

@pgetta pgetta self-assigned this Jun 26, 2026
@pgetta

pgetta commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Ah, I thought due to the rebase I've lost the approvals, but that's not the case. Merging now.

@pgetta pgetta merged commit a41fec2 into main Jun 26, 2026
2 checks passed
@pgetta pgetta deleted the feat/order-circuits-by-target-simulator branch June 26, 2026 08:39
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