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

  1. 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")
  1. Generate migration for it ./manage.py makemigrations
  2. Run test - it succeeds ✅
  3. 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),
          ),
      ]
    
  1. 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?)
  2. Remove all existing migration files and again generate migration ./manage.py makemigrations
  3. Run test again - - it succeeds ✅

Is is a bug, or do I make some kind of mistake in the code?

Change History (1)

comment:1 by Paweł Kotiuk, 4 hours ago

This bug may linked with

#28809 and #29058

Note: See TracTickets for help on using tickets.
Back to Top