Opened 4 hours ago
Last modified 4 hours ago
#36129 new Uncategorized
Geodjango migrations ignore change of dimension in MultiPointField
Reported by: | Paweł Kotiuk | Owned by: | |
---|---|---|---|
Component: | GIS | Version: | 5.1 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I think I found a bug in GeoDjango migration mechanism.
Reproduction
- Create a simple model
class MultiPointTester(models.Model): multipoint = models.MultiPointField( dim=2, blank=True, null=True, default="SRID=4326;MULTIPOINT EMPTY", )
and test for it
class MultipointTest(TransactionTestCase): def test_multipoint_creation(self): instance = models.MultiPointTester() instance.save() self.assertEqual(instance.multipoint.ewkt, "SRID=4326;MULTIPOINT EMPTY")
- Generate migration for it
./manage.py makemigrations
- Run test - it succeeds ✅
- Change dim from 2 to 3 and create migration
It contains migration like this (it does not mention dim change):
operations = [ migrations.AlterField( model_name='multipointtester', name='multipoint', field=django.contrib.gis.db.models.fields.MultiPointField( blank=True, default='SRID=4326;MULTIPOINT EMPTY', null=True, srid=4326), ), ]
- Run test again - it fails ❌ with error:
E ValueError: Cannot alter field test.MultiPointTester.multipoint into test.MultiPointTester.multipoint - they do not properly define db_type (are you using a badly-written custom field?)
- Remove all existing migration files and again generate migration
./manage.py makemigrations
- Run test again - - it succeeds ✅
Is is a bug, or do I make some kind of mistake in the code?
Note:
See TracTickets
for help on using tickets.
This bug may linked with
#28809 and #29058