add test for same named subclass in different apps

This commit is contained in:
Brian Kohan 2026-01-12 11:21:48 -08:00
parent 1384a0e034
commit 57a104f527
No known key found for this signature in database
GPG Key ID: 5C6CE8BA38C43FC1
9 changed files with 68 additions and 7 deletions

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2026-01-12 11:07
# Generated by Django 4.2 on 2026-01-12 13:15
from decimal import Decimal
from django.conf import settings

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2026-01-12 11:07
# Generated by Django 4.2 on 2026-01-12 13:15
from django.db import migrations, models
import django.db.models.deletion

View File

@ -1,4 +1,4 @@
# Generated by Django 4.2 on 2026-01-12 11:07
# Generated by Django 4.2 on 2026-01-12 13:15
from django.conf import settings
from django.db import migrations, models
@ -14,8 +14,8 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0012_alter_user_first_name_max_length'),
('contenttypes', '0002_remove_content_type_name'),
('auth', '0012_alter_user_first_name_max_length'),
]
operations = [

View File

@ -0,0 +1,27 @@
# Generated by Django 4.2 on 2026-01-12 13:15
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('tests', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('participant', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, related_name='other_userprofile', serialize=False, to='tests.participant')),
('name', models.CharField(max_length=100)),
],
options={
'abstract': False,
},
bases=('tests.participant',),
),
]

View File

@ -0,0 +1,12 @@
from polymorphic.tests.models import Participant
from django.db import models
class UserProfile(Participant):
participant = models.OneToOneField(
Participant, parent_link=True, on_delete=models.CASCADE, related_name="other_userprofile"
)
name = models.CharField(max_length=100)
def __str__(self):
return self.name

View File

@ -0,0 +1,21 @@
from django.test import TestCase
from django.core.exceptions import FieldError
class TestCrossAppSubclasses(TestCase):
def test_samename_different_app_subclasses(self):
from polymorphic.tests.other.models import UserProfile as OtherUserProfile
from polymorphic.tests.models import Participant, UserProfile
p1 = Participant.objects.create()
p2 = UserProfile.objects.create(name="userprofile1")
p3 = OtherUserProfile.objects.create(name="otheruserprofile1")
assert set(Participant.objects.all()) == {p1, p2, p3}
with self.assertRaises(FieldError):
Participant.objects.filter(UserProfile___name="otheruserprofile1")
assert set(Participant.objects.filter(other__UserProfile___name="otheruserprofile1")) == {
p3
}

View File

@ -107,6 +107,7 @@ INSTALLED_APPS = (
"polymorphic",
"polymorphic.tests",
"polymorphic.tests.deletion",
"polymorphic.tests.other",
"polymorphic.tests.test_migrations",
"polymorphic.tests.examples.views",
)

View File

@ -868,11 +868,11 @@ wheels = [
[[package]]
name = "identify"
version = "2.6.15"
version = "2.6.16"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/ff/e7/685de97986c916a6d93b3876139e00eef26ad5bbbd61925d670ae8013449/identify-2.6.15.tar.gz", hash = "sha256:e4f4864b96c6557ef2a1e1c951771838f4edc9df3a72ec7118b338801b11c7bf", size = 99311, upload-time = "2025-10-02T17:43:40.631Z" }
sdist = { url = "https://files.pythonhosted.org/packages/5b/8d/e8b97e6bd3fb6fb271346f7981362f1e04d6a7463abd0de79e1fda17c067/identify-2.6.16.tar.gz", hash = "sha256:846857203b5511bbe94d5a352a48ef2359532bc8f6727b5544077a0dcfb24980", size = 99360, upload-time = "2026-01-12T18:58:58.201Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/0f/1c/e5fd8f973d4f375adb21565739498e2e9a1e54c858a97b9a8ccfdc81da9b/identify-2.6.15-py2.py3-none-any.whl", hash = "sha256:1181ef7608e00704db228516541eb83a88a9f94433a8c80bb9b5bd54b1d81757", size = 99183, upload-time = "2025-10-02T17:43:39.137Z" },
{ url = "https://files.pythonhosted.org/packages/b8/58/40fbbcefeda82364720eba5cf2270f98496bdfa19ea75b4cccae79c698e6/identify-2.6.16-py2.py3-none-any.whl", hash = "sha256:391ee4d77741d994189522896270b787aed8670389bfd60f326d677d64a6dfb0", size = 99202, upload-time = "2026-01-12T18:58:56.627Z" },
]
[[package]]