MCPcopy
hub / github.com/tortoise/tortoise-orm / deconstruct

Method deconstruct

tortoise/fields/base.py:549–592  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

547 return desc
548
549 def deconstruct(self) -> tuple[str, list[Any], dict[str, Any]]:
550 path = f"{self.__class__.__module__}.{self.__class__.__name__}"
551 kwargs: dict[str, Any] = {}
552 if self.source_field:
553 kwargs["source_field"] = self.source_field
554 if self.generated:
555 kwargs["generated"] = self.generated
556 if self.pk:
557 kwargs["primary_key"] = self.pk
558 if self.null:
559 kwargs["null"] = self.null
560 if self.default is not None:
561 kwargs["default"] = self.default
562 if self.unique:
563 kwargs["unique"] = self.unique
564 if self.index:
565 kwargs["db_index"] = self.index
566 if self.description is not None:
567 kwargs["description"] = self.description
568 if hasattr(self, "db_constraint"):
569 kwargs["db_constraint"] = getattr(self, "db_constraint")
570 if hasattr(self, "to_field") and getattr(self, "to_field") is not None:
571 kwargs["to_field"] = getattr(self, "to_field")
572 if self.has_db_default():
573 kwargs["db_default"] = self.db_default
574
575 signature = inspect.signature(self.__class__.__init__)
576 for name, param in signature.parameters.items():
577 if name in ("self", "args", "kwargs", "model", "validators", "db_default"):
578 continue
579 if name == "field_type" and self.__class__.__name__ == "ManyToManyFieldInstance":
580 continue
581 if name in kwargs:
582 continue
583 if not hasattr(self, name):
584 continue
585 value = getattr(self, name)
586 if name == "model_name" and value is not None:
587 if not isinstance(value, str) and hasattr(value, "_meta"):
588 value = f"{value._meta.app}.{value.__name__}"
589 if value is None and param.default is None:
590 continue
591 kwargs[name] = value
592 return path, [], kwargs

Callers

nothing calls this directly

Calls 2

has_db_defaultMethod · 0.95
itemsMethod · 0.80

Tested by

no test coverage detected