Skip to content

feat: Sortable Collections#660

Open
bencap wants to merge 3 commits intorelease-2026.1.1from
feature/bencap/612/sortable-collections
Open

feat: Sortable Collections#660
bencap wants to merge 3 commits intorelease-2026.1.1from
feature/bencap/612/sortable-collections

Conversation

@bencap
Copy link
Collaborator

@bencap bencap commented Feb 17, 2026

This pull request introduces ordered many-to-many relationships between Collection and both Experiment and ScoreSet models, enabling explicit user-controlled ordering of experiments and score sets within collections. It replaces the previous association tables with new association models that include a position column, updates the database schema accordingly, and refactors related ORM logic and API endpoints to support these changes.

Database schema and association model changes:

  • Added new association models CollectionExperimentAssociation and CollectionScoreSetAssociation with a position column to maintain ordering in the collection_experiments and collection_score_sets tables. The corresponding Alembic migration adds the position column and backfills existing data to preserve deterministic order. [1] [2] [3]

ORM and model refactoring:

  • Refactored the Collection model to use the new association models for relationships with experiments and score sets, providing ordered access via association proxies. Removed the old association tables and updated related imports. [1] [2] [3]
  • Updated Experiment and ScoreSet models to use view-only relationships to collections via the new association tables, ensuring correct ORM behavior without direct modification from their side. [1] [2] [3] [4] [5]

API and business logic updates:

  • Refactored collection creation and update endpoints to build and manage association objects with explicit positions, preserving and updating the order of experiments and score sets as specified by the user. [1] [2] [3] [4]
  • Updated API logic for fetching and listing collections to filter associations (not just direct objects) based on user permissions, ensuring that ordering is preserved in API responses. [1] [2]

Minor utility and import adjustments:

  • Updated imports throughout the codebase to reflect the new association model structure and maintain code consistency. [1] [2]

…to_urn_list` that allows controllable behavior for superseding score sets
Add sortable collections feature allowing users to specify and maintain
custom ordering of score sets and experiments within collections across
all API operations (CREATE, GET, PATCH, POST, DELETE).

Key Changes:
- Replace simple many-to-many relationships with association object
  pattern using full ORM models with position column
- Add CollectionScoreSetAssociation and CollectionExperimentAssociation
  models with position tracking
- Use SQLAlchemy AssociationProxy for transparent access to related
  objects while maintaining ordered relationships
- Implement position-based ordering in all collection endpoints

API Behavior:
- POST endpoints append new items to end of collection
- PATCH endpoint uses replace-all semantics with implicit add/remove
- DELETE endpoints remove items and re-index remaining positions
- GET endpoints return items in user-specified order
- Permission escalation checks for PATCH when membership changes

Database Migration:
- Add position column to collection association tables
- Backfill with sequential positions using ROW_NUMBER() window function
  partitioned by collection_id for deterministic ordering
- Remove server default after backfill for application control

Testing:
- Add 14 comprehensive router tests for ordering functionality
- Test order preservation, reordering, appending, removal, implicit
  add/remove, error handling, and permission enforcement
- Add 3 view model tests for ORM-to-view order preservation
- Fix test helpers to track experiment URN changes during publishing

The implementation is fully backward compatible with existing API
clients and maintains all previous functionality via AssociationProxy.
@bencap bencap linked an issue Feb 17, 2026 that may be closed by this pull request
@bencap bencap removed a link to an issue Feb 17, 2026
@bencap bencap linked an issue Feb 17, 2026 that may be closed by this pull request
@bencap bencap marked this pull request as ready for review February 17, 2026 03:01
@bencap bencap requested review from jstone-dev and sallybg February 17, 2026 23:29
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.

Sortable collections

1 participant

Comments