Skip to content

fix: support non-integer PKs in NotificationMessage (fixes UUID overflow) - #12162

Merged
SchrodingersGat merged 1 commit into
inventree:masterfrom
kaizeenn:fix/12131-notification-uuid-pk
Jun 14, 2026
Merged

SchrodingersGat merged 1 commit into
inventree:masterfrom
kaizeenn:fix/12131-notification-uuid-pk

Conversation

@kaizeenn

Copy link
Copy Markdown
Contributor

Summary

Fixes #12131.

NotificationMessage.target_object_id and source_object_id were declared as PositiveIntegerField. This works fine for models with integer PKs, but overflows when the referenced model uses a UUID primary key — for example MachineConfig, which defines:

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

Django's GenericForeignKey stores the PK value as a string regardless of its original type, so the backing database column should be a CharField to accommodate any PK type (integer, UUID, slug, etc.).

Root cause

psycopg.errors.NumericValueOutOfRange: value "137023719040805274638741863464503989598" is out of range for type integer

The UUID is cast to an integer by the database driver, which overflows integer (max ~2.1 billion).

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 one assertion from integer 1 to str(1) since CharField stores the PK as a string

Backwards compatibility

Existing rows with integer PKs are unaffected — CharField stores them as '1', '2', etc. Django's GenericForeignKey resolution already casts the stored string back to the target model's PK type via ContentType.get_object_for_this_type(), so lookups continue to work correctly for both integer and UUID PKs.

…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]>
@netlify

netlify Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

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

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

@codecov

codecov Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.47%. Comparing base (2b4f303) to head (87f6ee0).
⚠️ Report is 384 commits behind head on master.

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           
Flag Coverage Δ
backend 90.53% <100.00%> (+<0.01%) ⬆️

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

Components Coverage Δ
Backend Apps 92.06% <100.00%> (+<0.01%) ⬆️
Backend General 93.53% <100.00%> (+<0.01%) ⬆️
Frontend 79.34% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat
SchrodingersGat merged commit 9706bc6 into inventree:master Jun 14, 2026
40 checks passed
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]>
@psxjt5 psxjt5 mentioned this pull request Aug 9, 2026
1 task done
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.

Notification UUID/PK Triggering Error

3 participants