Skip to content

feat(backend): Add generic API helper for transitions - #12693

Merged
SchrodingersGat merged 36 commits into
inventree:masterfrom
matmair:add-generic-transaction
Sep 29, 2026
Merged

SchrodingersGat merged 36 commits into
inventree:masterfrom
matmair:add-generic-transaction

Conversation

@matmair

@matmair matmair commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

This PR adds a generic viewset mixin that enables writing much more concise APIs when using FSM transitions - follow up to #12317

@netlify

netlify Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit 64f8ee6
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6aba102aed13e900080655d8

@matmair matmair added api Relates to the API refactor labels Aug 23, 2026
@matmair matmair added this to the 1.6.0 milestone Aug 23, 2026
@codecov

codecov Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.30769% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.44%. Comparing base (c2b7f71) to head (64f8ee6).

❌ 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     
Flag Coverage Δ
backend 92.04% <82.30%> (-0.05%) ⬇️

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

Components Coverage Δ
Backend Apps 92.65% <81.81%> (-0.06%) ⬇️
Backend General 94.52% <80.50%> (-0.44%) ⬇️
Frontend 79.88% <ø> (+0.31%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matmair

matmair commented Aug 23, 2026

Copy link
Copy Markdown
Member Author

@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

@matmair matmair changed the title feat(backend): Add generic api helper for transitions feat(backend): Add generic API helper for transitions Aug 23, 2026
@matmair matmair mentioned this pull request Aug 23, 2026
@matmair
matmair marked this pull request as ready for review August 26, 2026 22:40
@matmair

matmair commented Aug 27, 2026

Copy link
Copy Markdown
Member Author

@SchrodingersGat ready for review

@SchrodingersGat SchrodingersGat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you also apply these helpers to the build model API endpoints?

Comment thread src/backend/InvenTree/order/api.py
@matmair

matmair commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

Can you also apply these helpers to the build model API endpoints?

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

@matmair
matmair marked this pull request as draft September 7, 2026 20:22
@matmair

matmair commented Sep 7, 2026

Copy link
Copy Markdown
Member Author

i just found a potential information leak in this approach; must review options

@matmair
matmair marked this pull request as ready for review September 16, 2026 07:40
@matmair

matmair commented Sep 18, 2026

Copy link
Copy Markdown
Member Author

@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}'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can this be removed now?

@matmair matmair Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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('_', '-')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you going to implement this TODO?

@matmair matmair Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that would be breaking; I would want to wail till 2.0 for that; also see line 130

Comment thread src/backend/InvenTree/generic/states/api_helpers.py Outdated
@SchrodingersGat

SchrodingersGat commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

@matmair thanks for this, I'm happy to merge now and we can test this as we prepare for the 1.6.0 release

To confirm - are you happy this is good to merge?

@matmair

matmair commented Sep 29, 2026 •

Copy link
Copy Markdown
Member Author

@SchrodingersGat Yes this is ready for merge

Should we also try to include the refactor of the build endpoints in 1.6?

@SchrodingersGat
SchrodingersGat merged commit 9478c25 into inventree:master Sep 29, 2026
47 of 48 checks passed
@SchrodingersGat
SchrodingersGat deleted the add-generic-transaction branch September 29, 2026 11:26
@SchrodingersGat

Copy link
Copy Markdown
Member

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?

adityakrmishra added a commit to adityakrmishra/InvenTree that referenced this pull request Oct 1, 2026
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Relates to the API refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants