-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Feature: Unified Image Storage using InvenTreeImage Model #10484
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #10484 +/- ##
==========================================
+ Coverage 87.92% 88.09% +0.16%
==========================================
Files 1278 1286 +8
Lines 57447 58045 +598
Branches 2005 1993 -12
==========================================
+ Hits 50512 51133 +621
+ Misses 6437 6416 -21
+ Partials 498 496 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@Reza98Sh some CI tests are not passing, please address that before we start reviews |
|
Could we change the API references from |
for part that have multiple images "images": [
{
"pk": 0,
"primary": true,
"image": "http://example.com/",
"thumbnail": "string"
}
],
"image_url": "string",
"thumbnail_url": "string",but for company image that only have one image: "image": {
"pk": 1,
"primary": true,
"image": "/media/images/company_3_img_OAbJ7MY.jpg",
"thumbnail": "/media/images/company_3_img_OAbJ7MY.thumbnail.jpg"
},
"image_url": "string",
"thumbnail_url": "string",What do you think about this change? |
|
Maybe I have not communicated the goal good enough: current users of the API have request with the fields |
|
I noticed the confusion came from turning image and thumbnail from simple URL fields into objects after moving images to a separate table. To avoid naming conflicts and keep the API backward-compatible, I’ll remove the embedded image object from Part and Company serializers. Instead, these endpoints will once again return image and thumbnail as URL fields — just like before. They will again return image and thumbnail as URLs, while detailed image data can be fetched from the new /api/image/ endpoint. |
|
You can extend the fields as much as you want, but renaming old fields without a good reason is an issue. |
|
@Reza98Sh are you ok with me implementing some of the open comments? Would like to get this over the line |
|
I’ve been quite busy over the past couple of weeks. I’ve reviewed the context, and your review makes perfect sense. I will work on implementing these changes and plan to push the new code within the next few days. Thanks you! |
|
@matmair |
…image duplication and migration.
6b78e03 to
41b3f36
Compare
…ueryset and update filters
|
I’ve added several tests for the migrations. However, the code coverage report is flagging the test file itself (src/backend/InvenTree/common/test_migrations.py) for low coverage ! |
a519343 to
8e49133
Compare
|
@Reza98Sh touching up areas of the frontend that are changed without coverage would be great. We use Playwright for frontend tests, the framework has a pretty great vscode extension that I would recommend and is well-supported by copilot and other AI agents if you run into issues. The tests are in |
|
Some test are not passing, which is why the files are getting flagged; solving the test not passing should adress the code coverage issues or make them much less significant |
|
Most of the failing test seem to related to the renaming / removal / change of default behavior (None if nothing is set, not a blank image reference) on the image and thumbnail fields; which is what I was warning about above we can either change the name in the tests or of the fields to address that |
… in serializers, and refactor image components for better integration
…handling components
…fallback logic and action button integration
5e5aefd to
e6ff0b2
Compare
db41564 to
a0ced07
Compare
|
I’ve fixed the failed tests related to the database. Now I need some help with the remaining CI failures. Could you guide me on how to pass these tests? QC / Style [Typecheck] I couldn't find test files related to |
|
|
|
The response schema for the part and company list/detail endpoint remains unchanged. However, for adding and deleting images for parts, the old API approach can no longer be used because it may have multiple images. What is your suggestion? |
5ea92f5 to
329ded9
Compare
|
@matmair |
|
If it needs further changes or refinement, please feel free to let me know. |

This pull request introduces a major refactoring of the image management system, transitioning from a distributed approach to a unified, single-table architecture. By centralizing image storage into a new
InvenTreeImagemodel, this change simplifies the database schema, reduces data duplication, and provides a more robust and extensible foundation for handling images across the application.This work is a continuation of the efforts and discussions from the previous pull request (#10069)
Key Architectural Changes & Features
InvenTreeImageModel: All uploaded images are now stored in a singleInvenTreeImagetable (previously namedUploadedImage). This model uses a Generic Foreign Key to associate images with various other models (e.g.,Part,Company), making the system highly extensible for future use cases and plugins.sha256hash is now calculated and stored for each uploaded image. The system uses this hash to prevent identical images from being stored multiple times, saving significant storage space.os.pathtopathlib.Pathfor improved cross-platform compatibility and code readability.CustomStdImageFieldhas been implemented, which automatically deletes image files from the storage when the corresponding database record is removed, preventing orphaned files.InvenTreeImageSerializerMixinprovidesimage_urlandthumbnail_urlfields, ensuring consistent and efficient image serialization across different API endpoints while mitigating N+1 query problems.Tasks Completed
InvenTreeImage).PartandCompanyimages to the new table.InvenTreeImagemodel through a dedicated API namespace.masterbranch.TestLegacyImageMigration).New API Endpoints
A new API namespace for images has been introduced:
GET/api/image/POST/api/image/GET/api/image/<pk>/PATCH/api/image/<pk>/DELETE/api/image/<pk>/GET/api/image/thumbs/Addressing Previous Feedback
Based on the review of PR #10069, the following changes were made:
UploadedImagewas renamed toInvenTreeImagefor clarity.GenericForeignKeyinstead of a custom implementation, improving integration possibilities for plugins.InvenTreeImagemodel are now located incommon/, while model-specific tests (e.g., forPart) remain in their respective app directories.This PR is now complete, with all tests passing and functionality fully implemented. It is ready for a final review.
Related Issues
Closes #9788
Supersedes #10069