Repository navigation
fix: support non-integer PKs in NotificationMessage (fixes UUID overflow) - #12162
Merged
SchrodingersGat merged 1 commit intoJun 14, 2026
Merged
Conversation
…low) NotificationMessage.target_object_id and source_object_id were typed as PositiveIntegerField, which overflows when the referenced model uses a UUID primary key (e.g. MachineConfig). Django's GenericForeignKey stores the PK as a string in the database, so the field type should be CharField to accommodate any PK type (int, UUID, slug, etc.). Changes: - common/models.py: change target_object_id and source_object_id from PositiveIntegerField to CharField(max_length=255) on NotificationMessage - common/migrations/0044: AlterField migration for both columns - order/tests.py: update assertion from integer 1 to str(1) since CharField will now store the PK as a string Fixes inventree#12131 Signed-off-by: kaizeenn <[email protected]>
✅ Deploy Preview for inventree-web-pui-preview canceled.
|
matmair
approved these changes
Jun 14, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12162 +/- ##
=======================================
Coverage 86.46% 86.47%
=======================================
Files 1387 1388 +1
Lines 89476 89480 +4
Branches 10125 10125
=======================================
+ Hits 77367 77374 +7
+ Misses 12045 12042 -3
Partials 64 64
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
martonmiklos
pushed a commit
to martonmiklos/InvenTree
that referenced
this pull request
Jun 30, 2026
…low) (inventree#12162) NotificationMessage.target_object_id and source_object_id were typed as PositiveIntegerField, which overflows when the referenced model uses a UUID primary key (e.g. MachineConfig). Django's GenericForeignKey stores the PK as a string in the database, so the field type should be CharField to accommodate any PK type (int, UUID, slug, etc.). Changes: - common/models.py: change target_object_id and source_object_id from PositiveIntegerField to CharField(max_length=255) on NotificationMessage - common/migrations/0044: AlterField migration for both columns - order/tests.py: update assertion from integer 1 to str(1) since CharField will now store the PK as a string Fixes inventree#12131 Signed-off-by: kaizeenn <[email protected]>
martonmiklos
pushed a commit
to martonmiklos/InvenTree
that referenced
this pull request
Jun 30, 2026
…low) (inventree#12162) NotificationMessage.target_object_id and source_object_id were typed as PositiveIntegerField, which overflows when the referenced model uses a UUID primary key (e.g. MachineConfig). Django's GenericForeignKey stores the PK as a string in the database, so the field type should be CharField to accommodate any PK type (int, UUID, slug, etc.). Changes: - common/models.py: change target_object_id and source_object_id from PositiveIntegerField to CharField(max_length=255) on NotificationMessage - common/migrations/0044: AlterField migration for both columns - order/tests.py: update assertion from integer 1 to str(1) since CharField will now store the PK as a string Fixes inventree#12131 Signed-off-by: kaizeenn <[email protected]>
mahekp05
pushed a commit
to mahekp05/InvenTree
that referenced
this pull request
Aug 4, 2026
…low) (inventree#12162) NotificationMessage.target_object_id and source_object_id were typed as PositiveIntegerField, which overflows when the referenced model uses a UUID primary key (e.g. MachineConfig). Django's GenericForeignKey stores the PK as a string in the database, so the field type should be CharField to accommodate any PK type (int, UUID, slug, etc.). Changes: - common/models.py: change target_object_id and source_object_id from PositiveIntegerField to CharField(max_length=255) on NotificationMessage - common/migrations/0044: AlterField migration for both columns - order/tests.py: update assertion from integer 1 to str(1) since CharField will now store the PK as a string Fixes inventree#12131 Signed-off-by: kaizeenn <[email protected]>
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12131.
NotificationMessage.target_object_idandsource_object_idwere declared asPositiveIntegerField. This works fine for models with integer PKs, but overflows when the referenced model uses a UUID primary key — for exampleMachineConfig, which defines:Django's
GenericForeignKeystores the PK value as a string regardless of its original type, so the backing database column should be aCharFieldto accommodate any PK type (integer, UUID, slug, etc.).Root cause
The UUID is cast to an integer by the database driver, which overflows
integer(max ~2.1 billion).Changes
common/models.py: changetarget_object_idandsource_object_idfromPositiveIntegerFieldtoCharField(max_length=255)onNotificationMessagecommon/migrations/0044:AlterFieldmigration for both columnsorder/tests.py: update one assertion from integer1tostr(1)sinceCharFieldstores the PK as a stringBackwards compatibility
Existing rows with integer PKs are unaffected —
CharFieldstores them as'1','2', etc. Django'sGenericForeignKeyresolution already casts the stored string back to the target model's PK type viaContentType.get_object_for_this_type(), so lookups continue to work correctly for both integer and UUID PKs.