Skip to content

Preserve validation details when rendering labels - #12874

Merged
SchrodingersGat merged 3 commits into
inventree:masterfrom
ledvinap:fix/label-rendering-validation-errors
Sep 22, 2026
Merged

SchrodingersGat merged 3 commits into
inventree:masterfrom
ledvinap:fix/label-rendering-validation-errors

Conversation

@ledvinap

Copy link
Copy Markdown
Contributor

Label rendering wrappers currently replace all exceptions with generic “Error rendering label to PDF/HTML” messages, losing useful validation details raised by upstream template tags or plugins.

Handle ValidationError separately in both wrappers and re-raise it unchanged. Preserve existing logging, including for validation failures, so diagnostics remain available after failed DataOutput records are deleted. Unexpected exceptions retain their existing generic messages.

This fix applies independently to master. Together with #12872, the specific validation details are also retained in failed results and logging can be removed.

Mocked tests cover validation-detail preservation, logging, and unchanged handling of unexpected exceptions in both wrappers. Focused tests, Ruff checks, and git diff --check pass; the full suite was not run.

Keep logging validation errors in both rendering wrappers before re-raising the original exception. LabelTemplate.print deletes failed DataOutput records, so the error log preserves the diagnostic after the result is removed.

Update the mocked tests to require logging while retaining the original validation details.
@netlify

netlify Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

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

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

@matmair

matmair commented Sep 17, 2026

Copy link
Copy Markdown
Member

Have you tested and ensured that no internal information or secrets are leaked to unprivileged user through all possible error messages?

@ledvinap

Copy link
Copy Markdown
Contributor Author

Have you tested and ensured that no internal information or secrets are leaked to unprivileged user through all possible error messages?

Fair point.

I did not consider ValidationError as dangerous in this respect. It is normally user-facing problem.
Also report code does return validation errors (https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/models.py#L584-L586, https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/report/models.py#L623-L625), this PR extends that behavior to label wrappers; but that does not prove it to be safe.

My personal/developer-centric opinion is that its value outweighs negatives.

AI analysis:

• Current built-in validation messages can include internal details and raw template values:

  • Arithmetic tags include both operands and their Python types through debug_vars() (report/templatetags/report.py).
  • Currency tags include rejected amounts, multipliers, and currency codes.
  • File-path validation includes the supplied path.
  • Locale validation includes the locale and underlying exception text.

Other messages are fixed descriptions, such as missing QR-code data or an invalid model argument.

I haven’t identified an explicit credential disclosure in these inspected messages, but operands or paths could contain information the printing user should not see. ValidationError does not guarantee a sanitized message.

@matmair

matmair commented Sep 17, 2026

Copy link
Copy Markdown
Member
  1. follow the contributions document; if you setup your repo correctly with prek it is not possible to cause this CI failure
  2. i am not really a fan of the added test runtimes, especially seeing that this is a pattern in your PRs (see Preserve label printing failures and skip failed job redelivery #12872) but I will let @SchrodingersGat decide

@ledvinap

Copy link
Copy Markdown
Contributor Author
  1. follow the contributions document; if you setup your repo correctly with prek it is not possible to cause this CI failure

Sorry, fixed now, using extra commit; should I add new commits or force-push in future?

  1. i am not really a fan of the added test runtimes, especially seeing that this is a pattern in your PRs (see Preserve label printing failures and skip failed job redelivery #12872) but I will let @SchrodingersGat decide

I'll adapt as requested. GPT is generating the tests, I just verify that they make sense and do not test that 1+1 is still 2. With AI tools, it is usually better to have more tests to avoid missing something.

In this concrete case the tests are pretty cheap, so more code to review is probably bigger problem. But I did not test other PRS yet, it may be worse.


AI:

Measured both added tests locally, including discovery, class/test setup and teardown, plugin construction, mocks, and assertions:

Mode, 100 repetitions Median 95th percentile
Normal 6.1 ms 6.8 ms
With project coverage settings 15.3 ms 16.4 ms

Running them as a standalone Django command took 4.57 seconds median across five fresh processes, including startup and shutdown. That startup cost is already paid when they run inside the existing suite.

They require no database setup, fixtures, or actual rendering. Estimated incremental suite cost is therefore approximately 6–15 ms locally.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.79%. Comparing base (3a0ade3) to head (e5ab475).
⚠️ Report is 2 commits behind head on master.

❌ Your project check has failed because the head coverage (88.17%) is below the target coverage (92.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12874      +/-   ##
==========================================
- Coverage   87.26%   86.79%   -0.47%     
==========================================
  Files        1502     1502              
  Lines      102169   103017     +848     
  Branches    11661    11661              
==========================================
+ Hits        89156    89416     +260     
- Misses      12948    13536     +588     
  Partials       65       65              
Flag Coverage Δ
backend 91.89% <100.00%> (+0.02%) ⬆️

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

Components Coverage Δ
Backend Apps 91.53% <100.00%> (-1.01%) ⬇️
Backend General 88.17% <ø> (-6.56%) ⬇️
Frontend 79.82% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit 5edf72e into inventree:master Sep 22, 2026
46 of 48 checks passed
@SchrodingersGat

Copy link
Copy Markdown
Member

Happy with this overall, thanks for the implementation @ledvinap

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.

3 participants