﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26333	GIS geometries classes should be deconstructibles.	simondrabble	Nicolas Noé	"Given:

{{{
    from django.contrib.gis.db import models as gis
    from django.contrib.gis.geos import Point
    from django.db import models
    
    POINT = Point(-104.9903, 39.7392, srid=4326)
    
    class PagedModel(models.Model):
        objects = gis.GeoManager()
        location = gis.PointField(srid=4326, default=POINT)
}}}

then

{{{
python manage.py makemigration
python manage.py migrate
}}}

Observed:

{{{
  File ""./manage.py"", line 10, in <module>
    execute_from_command_line(sys.argv)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/core/management/__init__.py"", line 354, in execute_from_command_line
    utility.execute()
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/core/management/__init__.py"", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/core/management/base.py"", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/core/management/base.py"", line 445, in execute
    output = self.handle(*args, **options)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/core/management/commands/migrate.py"", line 222, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 110, in migrate
    self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/migrations/executor.py"", line 148, in apply_migration
    state = migration.apply(state, schema_editor)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/migrations/migration.py"", line 115, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/migrations/operations/fields.py"", line 62, in database_forwards
    field,
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/schema.py"", line 94, in add_field
    super(PostGISSchemaEditor, self).add_field(model, field)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/backends/base/schema.py"", line 384, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/contrib/gis/db/backends/postgis/schema.py"", line 30, in column_sql
    column_sql = super(PostGISSchemaEditor, self).column_sql(model, field, include_default)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/backends/base/schema.py"", line 146, in column_sql
    default_value = self.effective_default(field)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/db/backends/base/schema.py"", line 211, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py"", line 307, in get_db_prep_save
    return connection.ops.Adapter(self.get_prep_value(value))
  File ""/pyenv/django1.8/lib/python2.7/site-packages/django/contrib/gis/db/models/fields.py"", line 210, in get_prep_value
    raise ValueError('Cannot use object with type %s for a geometry lookup parameter.' % type(geom).__name__)
ValueError: Cannot use object with type float for a geometry lookup parameter.
}}}

Expected:

Migration completes successfully.

Hand-editing the generate migration file to use the Point class results in success.

IOW, changing:

{{{
            field=django.contrib.gis.db.models.fields.PointField(default=(-104.9903, 39.7392), srid=4326),
}}}

to

{{{
            field=django.contrib.gis.db.models.fields.PointField(default=Point(-104.9903, 39.7392, srid=4326)),
}}}

resolves the issue."	Bug	closed	GIS	1.8	Normal	fixed	makemigration gis point pointfield		Accepted	1	0	0	0	0	0
