Repository navigation
feat(backend): Add generic API helper for transitions - #12693
Conversation
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
Codecov Report❌ Patch coverage is ❌ Your patch check has failed because the patch coverage (80.50%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #12693 +/- ##
==========================================
+ Coverage 87.31% 87.44% +0.13%
==========================================
Files 1508 1508
Lines 103755 103582 -173
Branches 11790 11657 -133
==========================================
- Hits 90591 90579 -12
+ Misses 13098 12939 -159
+ Partials 66 64 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@SchrodingersGat @wolflu05 what do you think about this approach? I use it in some of my plugins, it was partially implemented automatically by Claude due to the high level of duplication in a model with a lot of transitions |
|
@SchrodingersGat ready for review |
SchrodingersGat
left a comment
There was a problem hiding this comment.
Can you also apply these helpers to the build model API endpoints?
…add-generic-transaction
this new generic approach only applies to DRF viewsets, not GenericViews and the build APIs are not on viewsets yet so that would expand the scope of the PR quite a bit |
|
i just found a potential information leak in this approach; must review options |
…add-generic-transaction
…add-generic-transaction
|
@SchrodingersGat the info leak in the transitions table is resolved now; this is ready for review |
| attr_name = name or method_name | ||
| segment = url_path or attr_name.replace('_', '-') | ||
| # TODO @matmair move all transition actions under the common prefix | ||
| # path = f'{TRANSITION_URL_PREFIX}/{segment}' |
There was a problem hiding this comment.
can this be removed now?
There was a problem hiding this comment.
that would be breaking; I would want to wait till 2.0 for that
| A DRF ``@action``-decorated method, ready to assign as a viewset class attribute. | ||
| """ | ||
| attr_name = name or method_name | ||
| segment = url_path or attr_name.replace('_', '-') |
There was a problem hiding this comment.
Are you going to implement this TODO?
There was a problem hiding this comment.
that would be breaking; I would want to wail till 2.0 for that; also see line 130
|
@matmair thanks for this, I'm happy to merge now and we can test this as we prepare for the To confirm - are you happy this is good to merge? |
|
@SchrodingersGat Yes this is ready for merge Should we also try to include the refactor of the build endpoints in 1.6? |
Yes I would like to. Do you have any time to look into this? |
- api_version.py: Bump API version to v552 for RepairOrder endpoints (PR inventree#12072) Upstream claimed v551 for PR inventree#12693 (transitions docs); our entry is now v552. - generic/states/tests.py: Accept upstream's defensive assertGreaterEqual(>=12) assertions instead of the brittle assertEqual(==13). Our RepairOrderStatus adds a new status class to the registry, making the hardcoded 13 incorrect. - pui_repair.spec.ts: Add page.reload() after doCachedLogin() in both tests. Root cause of frontend failures: doCachedLogin() restores a saved browser state where the React app's in-memory settings cache still has REPAIRORDER_ENABLED=false, even though setSettingState() PATCH-ed it to true on the server. The reload() forces a fresh settings fetch, ensuring the 'Repair Orders' tab renders before Playwright tries to click it.
This PR adds a generic viewset mixin that enables writing much more concise APIs when using FSM transitions - follow up to #12317