fix: Use proper column name instead of attname (#573)

fix: Use proper column name instead of attname
This commit is contained in:
Serhii Tereshchenko 2023-06-16 16:34:47 +03:00 committed by GitHub
parent 6916342126
commit 0ec4ac5e38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 2 deletions

View file

@ -9,6 +9,7 @@ To be released
- Add support for `Python 3.12` (GH-#545)
- Drop support for `Python 3.7` (GH-#545)
- Swedish translation (GH-#561)
- Use proper column name instead of attname (GH-#573)
4.3.1 (2022-11-15)
------------------

View file

@ -194,7 +194,7 @@ class InheritanceQuerySet(InheritanceQuerySetMixin, QuerySet):
where_queries.append('(' + ' AND '.join([
'"{}"."{}" IS NOT NULL'.format(
model._meta.db_table,
field.attname, # Should this be something else?
field.column,
) for field in model._meta.parents.values()
]) + ')')

View file

@ -67,6 +67,12 @@ class InheritanceManagerTestChild3(InheritanceManagerTestParent):
parent_link=True, on_delete=models.CASCADE)
class InheritanceManagerTestChild3_1(InheritanceManagerTestParent):
parent_ptr = models.OneToOneField(
InheritanceManagerTestParent, db_column="custom_parent_ptr",
parent_link=True, on_delete=models.CASCADE)
class InheritanceManagerTestChild4(InheritanceManagerTestParent):
other_onetoone = models.OneToOneField(
InheritanceManagerTestParent, related_name='non_inheritance_relation',

View file

@ -5,6 +5,7 @@ from tests.models import (
InheritanceManagerTestChild1,
InheritanceManagerTestChild2,
InheritanceManagerTestChild3,
InheritanceManagerTestChild3_1,
InheritanceManagerTestChild4,
InheritanceManagerTestGrandChild1,
InheritanceManagerTestGrandChild1_2,
@ -141,6 +142,7 @@ class InheritanceManagerTests(TestCase):
'inheritancemanagertestchild1',
'inheritancemanagertestchild2',
'manual_onetoone', # this was set via parent_link & related_name
'inheritancemanagertestchild3_1',
'child4_onetoone',
]
self.assertEqual(set(results.subclasses),
@ -256,7 +258,9 @@ class InheritanceManagerUsingModelsTests(TestCase):
objs = InheritanceManagerTestParent.objects.select_subclasses().order_by('pk')
objsmodels = InheritanceManagerTestParent.objects.select_subclasses(
InheritanceManagerTestChild1, InheritanceManagerTestChild2,
InheritanceManagerTestChild3, InheritanceManagerTestChild4,
InheritanceManagerTestChild3,
InheritanceManagerTestChild3_1,
InheritanceManagerTestChild4,
InheritanceManagerTestGrandChild1,
InheritanceManagerTestGrandChild1_2).order_by('pk')
self.assertEqual(set(objs.subclasses), set(objsmodels.subclasses))
@ -278,6 +282,7 @@ class InheritanceManagerUsingModelsTests(TestCase):
models = (InheritanceManagerTestChild1,
InheritanceManagerTestChild2,
InheritanceManagerTestChild3,
InheritanceManagerTestChild3_1,
InheritanceManagerTestChild4,
InheritanceManagerTestGrandChild1,
InheritanceManagerTestGrandChild1_2)
@ -426,6 +431,12 @@ class InheritanceManagerUsingModelsTests(TestCase):
self.assertEqual([child3], list(results))
def test_limit_to_specific_subclass_with_custom_db_column(self):
item = InheritanceManagerTestChild3_1.objects.create()
results = InheritanceManagerTestParent.objects.instance_of(InheritanceManagerTestChild3_1)
self.assertEqual([item], list(results))
def test_limit_to_specific_grandchild_class(self):
grandchild1 = InheritanceManagerTestGrandChild1.objects.get()
results = InheritanceManagerTestParent.objects.instance_of(InheritanceManagerTestGrandChild1)