-
-
Notifications
You must be signed in to change notification settings - Fork 205
Beccagraber/dev 1229 move advanced features #6479
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
Draft
rgraber
wants to merge
20
commits into
refactor-subsequences-2025
Choose a base branch
from
beccagraber/dev-1229-move-advanced-features
base: refactor-subsequences-2025
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Beccagraber/dev 1229 move advanced features #6479
rgraber
wants to merge
20
commits into
refactor-subsequences-2025
from
beccagraber/dev-1229-move-advanced-features
Conversation
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.
🗒️ Checklist
#Support Docs Updates, if any<type>(<scope>)<!>: <title> DEV-1234Front endand/orBack endorworkflow📣 Summary
Move advanced features API to its own endpoints rather than going through the asset detail API.
📖 Description
Previously we enabled/modified advanced features on an asset by PATCHing the /api/v2/assets/ endpoint with a params dictionary specifying the desired actions. This PR moves that functionality to a new endpoint, /api/v2/assets//advanced-features and updates it so we only configure one action per question per request, which is done via POST. Actions are also given unique IDs so they can be changed via PATCHes to /api/v2/assets/<asset_uid>/advanced-features/<action_uid>.
💭 Notes
This is incompatible with the front end and will cause an infinite refresh if you try to open a question for advanced editing. All testing should be done with curl.
Contains a significant refactor of advanced actions. Instead of a a large JSON in Asset.advanced_features, actions are broken out into individual QuestionAdvancedAction objects, where each object holds the configuration for one action for one question, in-keeping with the new question-level action parameters (some of which were previously asset-level).
Among other things, this required significant changes to
migrate_advanced_features. That code and some other bits were moved intomodels.pyto avoid circular imports.After some consultation with the front end, the
advanced_featuresfield in the asset detail endpoint will have a link to the advanced features API endpoint, the same way we do for hooks and other nested objects.Older assets are migrated on the fly to use the new QuestionAdvancedAction objects as needed. Attempting to POST to an unmigrated asset will result in an error since it would be confusing if a user tried to POST what they thought was a new action but got a Uniqueness error because the action already existed inside advanced_features and we migrated it before trying to create a new one.
The migration assumes we only want to configure actions for questions in
Asset.known_cols, ie questions for which we know there exists at least one action response, like a transcription, translation, or QA answer. This does open us up to some risk if somehow theknown_colsof an asset got out of sync, but it is preferable to having to parse thecontentdict of an Asset, which is very slow.Another option was to use long_running_migrations, but ensuring correctness between migrating an old advanced_features dict and new actions possibly being created was very touchy, and still could have resulted in very slow requests while we locked the advanced features on an asset to do the migration. Similarly, we could have used a Django migration, but it would have been slow and have similar risks of conflict unless we actually disabled advanced features for a while.
This PR does not deal with how exactly the parameters for QualActions are migrated. That is being done in a separate PR.
👀 Preview steps
/api/v2/assets/<asset-uid>/advanced-featurescurl -X POST -H 'Authorization: Token <your token>' kf.kobo.local/api/v2/assets/<asset-uid>/advanced-features/ --json '{"action": "manual_translation", "question_xpath": <audio question xpath>, "params": [{"language": "es"}]}'/api/v2/assets/<asset-uid>/advanced-featurescurl -X PATCH -H 'Authorization: Token <your token>' kf.kobo.local/api/v2/assets/<asset-uid>/data/<submission-uuid>/supplement/ --json '{"_version":"20250820", "<audio question xpath>": {"manual_transcription": {"language":"en", "value": "hello"}}}'13.🟢 Request should fail with 'Invalid question name' (because actions are not enabled on this question)
curl -X POST -H 'Authorization: Token <your token>' kf.kobo.local/api/v2/assets/<asset-uid>/advanced-features/ --json '{"action": "manual_transcription", "question_xpath": <audio question xpath>, "params": [{"language": "en"}]}'curl -X PATCH -H 'Authorization: Token <your token>' kf.kobo.local/api/v2/assets/<asset-uid>/data/<submission-uuid>/supplement/ --json '{"_version":"20250820", "<audio question xpath>": {"manual_transcription": {"language":"es", "value": "hello"}}}'