[Django] #25276: It would be very nice if django AlterField raised an error when ordered to alter that doesn't exist

29 views
Skip to first unread message

Django

unread,
Aug 14, 2015, 9:31:30 AM8/14/15
to django-...@googlegroups.com
#25276: It would be very nice if django AlterField raised an error when ordered to
alter that doesn't exist
-----------------------------+--------------------
Reporter: jbzdak | Owner: nobody
Type: New feature | Status: new
Component: Migrations | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+--------------------
If I have following model in app ``foo``:

{{{#!python

class Foo(models.Model):
bar = modeld.CharField(max_length=500)

}}}

And I write (by hand) following migration:


{{{#!python

class Migration(migrations.Migration):

dependencies = [
('foo', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='foo',
name='baz', #Notice there is a typo in field name
field=modeld.CharField(max_length=100)
),
]

}}}

Currently this migration is a does nothing, however I feel that more
appropriate action would be to notify user that he is trying to alter
nonexistent field.

Current implementation is a NOOP because (see:
https://github.com/django/django/blob/master/django/db/migrations/operations/fields.py#L178)
it is implemented in following way:

{{{#!python
state.models[app_label, self.model_name_lower].fields = [
(n, field if n == self.name else f)
for n, f in
state.models[app_label, self.model_name_lower].fields
]
state.reload_model(app_label, self.model_name_lower)
}}}

If someone says this is a sensible feature request I may modify migration
code to raise if there is an error.

I have actually lost some hours of my life due to this behaviour when I
was writing a migration that moved models between applications.

--
Ticket URL: <https://code.djangoproject.com/ticket/25276>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 14, 2015, 9:43:34 AM8/14/15
to django-...@googlegroups.com
#25276: AlterField should raise an error when referenced field doesn't exist
--------------------------------------+------------------------------------
Reporter: jbzdak | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* version: 1.8 => master
* needs_docs: => 0
* type: New feature => Cleanup/optimization
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25276#comment:1>

Django

unread,
Jan 17, 2017, 1:03:33 PM1/17/17
to django-...@googlegroups.com
#25276: AlterField should raise an error when referenced field doesn't exist
--------------------------------------+------------------------------------
Reporter: Jacek Bzdak | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Anton Samarchyan):

* cc: desecho@… (added)


Comment:

I can't reproduce. I am getting `django.core.exceptions.FieldDoesNotExist:
Foo has no field named 'baz'`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25276#comment:2>

Django

unread,
Jan 17, 2017, 1:05:04 PM1/17/17
to django-...@googlegroups.com
#25276: AlterField should raise an error when referenced field doesn't exist
--------------------------------------+------------------------------------
Reporter: Jacek Bzdak | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Description changed by Anton Samarchyan:

Old description:

New description:

If I have following model in app `foo`:

{{{#!python

class Foo(models.Model):
bar = models.CharField(max_length=500)

}}}


{{{#!python

class Migration(migrations.Migration):

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25276#comment:3>

Django

unread,
Apr 12, 2017, 9:09:58 AM4/12/17
to django-...@googlegroups.com
#25276: AlterField should raise an error when referenced field doesn't exist
-------------------------------------+-------------------------------------

Reporter: Jacek Bzdak | Owner: nobody
Type: | Status: closed
Cleanup/optimization |

Component: Migrations | Version: master
Severity: Normal | Resolution:
| worksforme

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => worksforme


Comment:

I also can't reproduce.

--
Ticket URL: <https://code.djangoproject.com/ticket/25276#comment:4>

Reply all
Reply to author
Forward
0 new messages