mirror of
https://github.com/inventree/InvenTree.git
synced 2026-07-04 06:00:38 +00:00
fix: support non-integer PKs in NotificationMessage (fixes UUID overflow) (#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 #12131 Signed-off-by: kaizeenn <khairil0153@gmail.com>
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
"""Migration to change NotificationMessage object_id fields from PositiveIntegerField to CharField.
|
||||
|
||||
This allows notifications to reference models that use non-integer primary keys,
|
||||
such as UUIDField (e.g. MachineConfig), without a database overflow error.
|
||||
|
||||
See: https://github.com/inventree/InvenTree/issues/12131
|
||||
"""
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('common', '0043_auto_20260518_1206'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='notificationmessage',
|
||||
name='target_object_id',
|
||||
field=models.CharField(max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='notificationmessage',
|
||||
name='source_object_id',
|
||||
field=models.CharField(max_length=255, null=True, blank=True),
|
||||
),
|
||||
]
|
||||
@@ -1678,7 +1678,7 @@ class NotificationMessage(models.Model):
|
||||
ContentType, on_delete=models.CASCADE, related_name='notification_target'
|
||||
)
|
||||
|
||||
target_object_id = models.PositiveIntegerField()
|
||||
target_object_id = models.CharField(max_length=255)
|
||||
|
||||
target_object = GenericForeignKey('target_content_type', 'target_object_id')
|
||||
|
||||
@@ -1691,7 +1691,7 @@ class NotificationMessage(models.Model):
|
||||
blank=True,
|
||||
)
|
||||
|
||||
source_object_id = models.PositiveIntegerField(null=True, blank=True)
|
||||
source_object_id = models.CharField(max_length=255, null=True, blank=True)
|
||||
|
||||
source_object = GenericForeignKey('source_content_type', 'source_object_id')
|
||||
|
||||
|
||||
@@ -523,7 +523,7 @@ class OrderTest(ExchangeRateMixin, PluginRegistryMixin, TestCase):
|
||||
|
||||
msg = messages.first()
|
||||
|
||||
self.assertEqual(msg.target_object_id, 1)
|
||||
self.assertEqual(msg.target_object_id, str(1))
|
||||
self.assertEqual(msg.name, 'Overdue Purchase Order')
|
||||
|
||||
def test_new_po_notification(self):
|
||||
|
||||
Reference in New Issue
Block a user