clean conflicts and some cleaning
This commit is contained in:
@ -111,7 +111,6 @@ class ForeignKeyField(BaseField):
|
||||
def expand_relationship(
|
||||
cls, value: Any, child: "Model"
|
||||
) -> Optional[Union["Model", List["Model"]]]:
|
||||
print("expandong relatiknship", value, child)
|
||||
if value is None:
|
||||
return None
|
||||
|
||||
|
||||
@ -171,9 +171,7 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
|
||||
exclude_defaults: bool = False,
|
||||
exclude_none: bool = False,
|
||||
nested: bool = False
|
||||
) -> 'DictStrAny': # noqa: A003
|
||||
print('callin super', self.__class__)
|
||||
print('to exclude', self._exclude_related_names_not_required(nested))
|
||||
) -> 'DictStrAny': # noqa: A003'
|
||||
dict_instance = super().dict(include=include,
|
||||
exclude=self._exclude_related_names_not_required(nested),
|
||||
by_alias=by_alias,
|
||||
@ -181,9 +179,7 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
|
||||
exclude_unset=exclude_unset,
|
||||
exclude_defaults=exclude_defaults,
|
||||
exclude_none=exclude_none)
|
||||
print('after super')
|
||||
for field in self._extract_related_names():
|
||||
print(self.__class__, field, nested)
|
||||
nested_model = getattr(self, field)
|
||||
|
||||
if self.Meta.model_fields[field].virtual and nested:
|
||||
@ -191,13 +187,9 @@ class FakePydantic(pydantic.BaseModel, metaclass=ModelMetaclass):
|
||||
if isinstance(nested_model, list) and not isinstance(
|
||||
nested_model, ormar.Model
|
||||
):
|
||||
print('nested list')
|
||||
dict_instance[field] = [x.dict(nested=True) for x in nested_model]
|
||||
else:
|
||||
print('instance')
|
||||
if nested_model is not None:
|
||||
elif nested_model is not None:
|
||||
dict_instance[field] = nested_model.dict(nested=True)
|
||||
|
||||
return dict_instance
|
||||
|
||||
def from_dict(self, value_dict: Dict) -> None:
|
||||
|
||||
@ -113,11 +113,9 @@ def populate_pydantic_default_values(attrs: Dict) -> Dict:
|
||||
type_.name = field
|
||||
def_value = type_.default_value()
|
||||
curr_def_value = attrs.get(field, 'NONE')
|
||||
print(field, curr_def_value, 'def val', type_.nullable)
|
||||
if curr_def_value == 'NONE' and isinstance(def_value, FieldInfo):
|
||||
attrs[field] = def_value
|
||||
elif curr_def_value == 'NONE' and type_.nullable:
|
||||
print(field, 'defsults tp none')
|
||||
attrs[field] = FieldInfo(default=None)
|
||||
return attrs
|
||||
|
||||
@ -148,8 +146,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
|
||||
attrs["__annotations__"]= annotations
|
||||
attrs = populate_pydantic_default_values(attrs)
|
||||
|
||||
print(attrs)
|
||||
|
||||
tablename = name.lower() + "s"
|
||||
new_model.Meta.tablename = new_model.Meta.tablename or tablename
|
||||
|
||||
@ -182,8 +178,6 @@ class ModelMetaclass(pydantic.main.ModelMetaclass):
|
||||
)
|
||||
|
||||
new_model.Meta.model_fields = model_fields
|
||||
print(attrs, 'before super')
|
||||
print(new_model.Meta.__dict__)
|
||||
new_model = super().__new__( # type: ignore
|
||||
mcs, name, bases, attrs
|
||||
)
|
||||
|
||||
@ -79,7 +79,7 @@ class Query:
|
||||
|
||||
expr = self._apply_expression_modifiers(expr)
|
||||
|
||||
print(expr.compile(compile_kwargs={"literal_binds": True}))
|
||||
#print(expr.compile(compile_kwargs={"literal_binds": True}))
|
||||
self._reset_query_parameters()
|
||||
|
||||
return expr, self._select_related
|
||||
@ -179,7 +179,6 @@ class Query:
|
||||
):
|
||||
rel_part = field_name if not rel_part else rel_part + "__" + field_name
|
||||
if not field.nullable:
|
||||
print('add', rel_part, field)
|
||||
if rel_part not in self._select_related:
|
||||
new_related = "__".join(rel_part.split("__")[:-1]) if len(
|
||||
rel_part.split("__")) > 1 else rel_part
|
||||
@ -188,7 +187,7 @@ class Query:
|
||||
elif self._field_qualifies_to_deeper_search(
|
||||
field, parent_virtual, nested, rel_part
|
||||
):
|
||||
print('deeper', rel_part, field, field.to)
|
||||
|
||||
self._extract_auto_required_relations(
|
||||
prev_model=field.to,
|
||||
rel_part=rel_part,
|
||||
|
||||
@ -69,10 +69,8 @@ class RelationshipManager:
|
||||
|
||||
@staticmethod
|
||||
def append_related_model(relations_list: List["Model"], model: "Model") -> None:
|
||||
print("appending", relations_list, model)
|
||||
for relation_child in relations_list:
|
||||
try:
|
||||
print(relation_child.__same__(model), "same")
|
||||
if relation_child.__same__(model):
|
||||
return
|
||||
except ReferenceError:
|
||||
|
||||
@ -118,15 +118,14 @@ async def test_model_crud():
|
||||
await track2.save()
|
||||
await track3.save()
|
||||
|
||||
assert len(album.tracks) == 3
|
||||
assert album.tracks[1].title == "Heart don't stand a chance"
|
||||
|
||||
track = await Track.objects.get(title="The Bird")
|
||||
assert track.album.pk == album.pk
|
||||
assert track.album.name is None
|
||||
await track.album.load()
|
||||
assert track.album.name == "Malibu"
|
||||
|
||||
assert len(album.tracks) == 3
|
||||
assert album.tracks[1].title == "Heart don't stand a chance"
|
||||
|
||||
album1 = await Album.objects.get(name="Malibu")
|
||||
assert album1.pk == 1
|
||||
|
||||
Reference in New Issue
Block a user