Skip to content

Commit ff3a10a

Browse files
committed
fixed lint and failing test
1 parent 4b167a2 commit ff3a10a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ninja_schema/orm/utils/converter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def convert_django_field(field: Field, **kwargs: Any) -> Tuple[Type, FieldInfo]:
119119

120120

121121
@no_type_check
122-
def create_m2m_link_type(type_: Type[TModel], related_model: models.Model) -> Type[TModel]:
122+
def create_m2m_link_type(
123+
type_: Type[TModel], related_model: models.Model
124+
) -> Type[TModel]:
123125
class M2MLink(type_): # type: ignore
124126
@classmethod
125127
def __get_validators__(cls):
@@ -129,9 +131,9 @@ def __get_validators__(cls):
129131
def validate(cls, v):
130132
if isinstance(v, type_):
131133
return v
132-
if isinstance(v, related_model):
134+
if hasattr(v, "pk") and isinstance(v.pk, type_):
133135
return v.pk
134-
raise Exception('Invalid type')
136+
raise Exception("Invalid type")
135137

136138
return M2MLink
137139

0 commit comments

Comments
 (0)