Skip to content
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

Updates for metadata information #7343

Merged

Conversation

SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented May 26, 2024


This PR fixes a subtle bug which existed in our "metadata" implementation, which extracted database field information and provided it to the DRF API.

Any custom serializer fields which do not have an explicitly defined label would default to their attribute name, which was an untranslated string.

So, something like this:

image

Would result in a label value of "Category" (which is simply extracted from the name of the serializer field) even if it pointed to an underlying database model field. The "verbose_name" of the field (in this case Part Category) was not obtained.

Worse, the auto-generated labels were not exposed to the translation framework at any point. So, any custom DRF fields were never getting translated.


This patch adds some extra introspection steps, and will override a raw stirng value with a translated string value (if it exists). It also adds explicit mapping from verbose_name (on the model field) to label (on the serializer field).

Note: If a translated string exists on the serializer field it will not be overridden by the model field

- Override 'label' values with 'verbose_name' values
- Only if 'label' is *not* translated, but 'verbose_name' is
- Allows the translated model fields name to be pushed through to the metadata framework
@SchrodingersGat SchrodingersGat added the bug Identifies a bug which needs to be addressed label May 26, 2024
@SchrodingersGat SchrodingersGat added this to the 0.16.0 milestone May 26, 2024
Copy link

netlify bot commented May 26, 2024

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

Name Link
🔨 Latest commit 5edce1a
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/665428f3d7f61f0008f79924

Copy link

codecov bot commented May 26, 2024

Codecov Report

Attention: Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Project coverage is 83.78%. Comparing base (9f95dbe) to head (5edce1a).
Report is 325 commits behind head on master.

Files Patch % Lines
src/backend/InvenTree/InvenTree/metadata.py 90.47% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7343   +/-   ##
=======================================
  Coverage   83.78%   83.78%           
=======================================
  Files        1049     1049           
  Lines       46005    46031   +26     
  Branches     1386     1386           
=======================================
+ Hits        38545    38569   +24     
- Misses       7099     7101    +2     
  Partials      361      361           
Flag Coverage Δ
backend 85.14% <94.59%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

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

LGTM; Should we add tests for this (translation)?

@SchrodingersGat
Copy link
Member Author

LGTM; Should we add tests for this (translation)?

Yeah, I'll add some unit tests so that we don't get any regressions

@SchrodingersGat SchrodingersGat merged commit ea6bdd3 into inventree:master May 27, 2024
28 checks passed
@SchrodingersGat SchrodingersGat deleted the metadata-improvements branch May 27, 2024 06:55
martonmiklos pushed a commit to martonmiklos/InvenTree that referenced this pull request Jun 24, 2024
* Updates for metadata information

- Override 'label' values with 'verbose_name' values
- Only if 'label' is *not* translated, but 'verbose_name' is
- Allows the translated model fields name to be pushed through to the metadata framework

* Remove unused import

* Add unit testing for metadata lookup

* Update serializer: allow 'category' to be blank

* Bump API version

* Fix for unit test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Category" field of "Create Part" form is having problems
2 participants