Ticket #301 (closed defect: fixed)
Introspection error with no EOL at end of file with PointField
| Reported by: | jcd@… | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | 0.7 |
| Component: | commands | Version: | 0.6.2 |
| Keywords: | Introspection GIS | Cc: |
Description
I have an app called apps.cdla_apps.parkway, with three models, two of which have a PointField in them (both named coordinates). The file doesn't end with a newline, and when I run ./manage.py startmigration parkway --initial on it, the first PointField? (county.coordinates) gets introspected just fine, but the second one (location.coordinates) gets Nodefed, and issues a warning. If I change nothing in the file, but resave it with a text editor that adds a newline, It works just fine.
My model:
try:
from django.contrib.gis.db import models
except NotImplementedError:
from django.db import models
from django.contrib.localflavor.us import models as us_models
# Create your models here.
class County(models.Model):
county = models.CharField(max_length=64)
state = us_models.USStateField(default='NC')
coordinates = models.PointField(blank=True, null=True)
class Meta:
verbose_name_plural = 'Counties'
ordering = ('county',)
def __unicode__(self):
return u'%(county)s (%(state)s)' % self.__dict__
class Section(models.Model):
section = models.CharField(max_length=8)
description = models.CharField(max_length=64, blank=True)
mile_start = models.FloatField(blank=True, null=True, help_text='Milepost Start')
mile_stop = models.FloatField(blank=True, null=True, help_text='Milepost End')
class Meta(object):
ordering = (u'section',)
def __unicode__(self):
return u'%(section)s (%(description)s)' % self.__dict__
class Location(models.Model):
label = models.CharField(max_length=128, blank=True)
milepost = models.FloatField(blank=True, null=True)
county = models.ForeignKey(County, blank=True, null=True)
section = models.ForeignKey(Section, blank=True, null=True)
description = models.TextField(blank=True)
coordinates = models.PointField(blank=True, null=True)
class Meta:
ordering = ('label',)
def __unicode__(self):
return u'%(label)s' % self.__dict__
With no EOL:
jcdyer@aalcdl07:/cgi/django/brp/projects/brp$ ./manage.py startmigration parkway --initial Creating migrations directory at '/cgi/django/brp/apps/cdla_apps/parkway/migrations'... Creating __init__.py in '/cgi/django/brp/apps/cdla_apps/parkway/migrations'... + Added model 'parkway.Location' ( Nodefing field: coordinates WARNING: Cannot get definition for 'coordinates' on 'parkway.location'. Please edit the migration manually. + Added model 'parkway.County' ( Parsing field: coordinates + Added model 'parkway.Section' ( Parsing field: coordinates ( Nodefing field: coordinates WARNING: Cannot get definition for 'coordinates' on 'parkway.location'. Please edit the migration manually to define it, or add the south_field_triple method to it. Created 0001_initial.py.
With EOL:
jcdyer@aalcdl07:/cgi/django/brp/projects/brp$ ./manage.py startmigration parkway --initial Creating migrations directory at '/cgi/django/brp/apps/cdla_apps/parkway/migrations'... Creating __init__.py in '/cgi/django/brp/apps/cdla_apps/parkway/migrations'... + Added model 'parkway.Location' ( Parsing field: coordinates + Added model 'parkway.County' ( Parsing field: coordinates + Added model 'parkway.Section' ( Parsing field: coordinates ( Parsing field: coordinates Created 0001_initial.py.
The frozen model looks like this after the failed introspection:
models = {
'parkway.county': {
'coordinates': ('models.PointField', [], {'null': 'True', 'blank': 'True'}),
'county': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'state': ('django.contrib.localflavor.us.models.USStateField', [], {'default': "'NC'"})
},
'parkway.location': {
'coordinates': '<< PUT FIELD DEFINITION HERE >>',
'county': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['parkway.County']", 'null': 'True', 'blank': 'True'}),
'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'milepost': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'section': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['parkway.Section']", 'null': 'True', 'blank': 'True'})
},
'parkway.section': {
'description': ('django.db.models.fields.CharField', [], {'max_length': '64', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'mile_start': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'mile_stop': ('django.db.models.fields.FloatField', [], {'null': 'True', 'blank': 'True'}),
'section': ('django.db.models.fields.CharField', [], {'max_length': '8'})
}
}
complete_apps = ['parkway']
Attached are copies of the model file with and without newlines, as sensible editors make it difficult to replicate this issue. :)
Attachments
Change History
Changed 4 years ago by jcd@…
- Attachment fail_models.py added
Changed 4 years ago by jcd@…
- Attachment success_models.py added
models.py file that ends with newline
comment:1 Changed 4 years ago by jcd@…
Please forgive the verbosity of the models. I was having trouble trimming it down without fixing the problem. :)
comment:2 Changed 4 years ago by andrew
- Status changed from new to assigned
- Milestone set to 0.7
That's very odd; newlines shouldn't affect the introspector, it doesn't even look at the source file!
I've been rewriting the migration generator for 0.7 anyway, so hopefully this'll be solved there; I'll move it to the 0.7 milestone for verification. In the meantime, I suggest you add newlines...
(also, attaching a correctly-generated frozen models dict would help)

models.py file that ends without newline