[FIX] increment analysis order on POST instead of always 1#1617
Open
lobennett wants to merge 1 commit into
Open
[FIX] increment analysis order on POST instead of always 1#1617lobennett wants to merge 1 commit into
lobennett wants to merge 1 commit into
Conversation
AnalysisSchema.load_values read the study id from data['study_id'], but the pre_load payload carries it under the 'study' data_key, so the auto-order branch never ran and every new analysis got order 1. Resolve the id from 'study' (mirroring PointSchema), keeping the study_id fallback and a nested-object guard. Closes neurostuff#1580.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1580. Creating an analysis via
POST /api/analyses/without an explicitorderalways assignedorder = 1, so analyses never received a sequential order within their study.Root cause
AnalysisSchema.load_values(a@pre_loadhook) auto-assigns the order by querying the current max for the study:The field is declared
study_id = fields.String(data_key="study").@pre_loadruns on the raw payload, before marshmallow maps thedata_key, so the study id is present under the keystudy, notstudy_id.data.get("study_id")was therefore alwaysNone, theelsebranch always ran, and every new analysis gotorder = 1.Fix
Resolve the id from the
studydata_key (keeping thestudy_idfallback and a nested-object guard), mirroring the patternPointSchema.process_valuesalready uses for the identical case:AnalysisSchemais the only change;PointSchemaalready handled this correctly.Tests
The existing
test_post_analysis_without_orderonly assertedorder is not None, which passed even with the bug (order was1, notNone) — that gap let the bug through. Addstest_post_analyses_without_order_increments_within_study: creates a fresh study and POSTs two order-less analyses, asserting orders1then2. Fails on the old code (both1), passes with the fix.