--
Ticket URL: <https://code.djangoproject.com/ticket/17232>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
A quick question: Wouldn't this result in self._field_cache still having
the duplicate fields, it is just the _field_name_cache which is correct
now? You could also assert there aren't duplicate field attnames from
_different_ models. In multitable multi-inheritance having id-field in
more than one parent is an error, for example. Or maybe that should be
done in model validation?
--
Ticket URL: <https://code.djangoproject.com/ticket/17232#comment:1>
Comment (by hrharkins):
I'm not sure about the assertion -- other than the "id" field, which is
true should be duplicated for each level, the other "naked" fields would
seem to imply only one representation in a shared base class. I'm not
sure exactly how AutoFields deal with single inheritance otherwise -- they
are potentially multiple "id" fields stacked on different classes.
This raises a different question though (not a problem in my example or my
current project) -- suppose an external agent claims an ID of a subclass
that the base class would have wanted? Could this not cause a consistency
issue?
The correction suggested was purely out of nativity and trying to
understand the nature of the problem and a possible fix, so I am
definitely not implying that the above is likely to be a complete fix (it
is a feeble attempt after all :D ). Perhaps a better one would be:
{{{#!python
def _fill_fields_cache(self):
cache = []
for parent in self.parents:
for field, model in parent._meta.get_fields_with_model():
if model:
cache.append((field, model))
else:
cache.append((field, parent))
cache.extend([(f, None) for f in self.local_fields])
# Original line
#self._field_cache = tuple(cache)
# Second feeble attempt to avoid duplicates
recache = []
for field in cache:
if field not in recache:
recache.append(field)
self._field_cache = tuple(recache)
self._field_name_cache = [x for x, _ in cache]
}}}
This passes the unit tests above again, but I suspect there are other
subtleties out there to be dealt with too.
--
Ticket URL: <https://code.djangoproject.com/ticket/17232#comment:2>
Comment (by hrharkins):
(Sorry about the cut-and-paste issues on the last comment -- the version
shown is consistent with my version that passes tests)
--
Ticket URL: <https://code.djangoproject.com/ticket/17232#comment:3>
* status: new => closed
* resolution: => duplicate
Comment:
Looks like a duplicate of #10808.
--
Ticket URL: <https://code.djangoproject.com/ticket/17232#comment:4>