Opened 14 years ago

Closed 11 years ago

#14028 closed Bug (fixed)

setting db_column to same value as another column should not validate

Reported by: Anssi Kääriäinen Owned by: Helen Sherwood-Taylor
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: validation, sprintdec2010
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Consider having a model

class FooBar(models.Model):
    foo = models.IntegerField()
    bar = models.IntegerField(db_column='foo')
    class Meta:
        db_table = 'foobar'

This does not raise any validation errors, even though the model clearly is not valid.

Change History (10)

comment:1 by Thomas Ashelford, 13 years ago

Keywords: sprintdec2010 added
Owner: changed from nobody to Thomas Ashelford
Summary: setting db_column to same value than another column should not validatesetting db_column to same value as another column should not validate
Triage Stage: UnreviewedAccepted

Agreed, let's fix it. I'll work up a patch.

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: Bug

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Tim Graham, 11 years ago

Easy pickings: set

Seems like this would be a fairly easy addition to django/core/management/validation.py with a test in django/tests/invalid_models/tests.py.

comment:6 by Helen Sherwood-Taylor, 11 years ago

Owner: changed from Thomas Ashelford to Helen Sherwood-Taylor
Status: newassigned

Working on this at the PyConUK Django sprint

comment:7 by Helen Sherwood-Taylor, 11 years ago

Should it be valid to do something like this?

class FooBar(models.Model):
    foo = models.IntegerField(db_column='bar')
    bar = models.IntegerField(db_column='foo')
    class Meta:
        db_table = 'foobar'
Version 0, edited 11 years ago by Helen Sherwood-Taylor (next)

comment:8 by Helen Sherwood-Taylor, 11 years ago

Consensus on #django-dev was that this should be a valid model.

comment:9 by Helen Sherwood-Taylor, 11 years ago

I have created a pull request which fixes this:

https://github.com/django/django/pull/1664

comment:10 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: assignedclosed

In 41167645b1039067127fa215d4d28296bfa4cfdc:

Fixed #14028 - Added validation for clashing db_columns.

Thanks akaariai for the suggestion.

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