def serialize(
        self: "Model",
        value: Optional["Model"],
        handler: SerializerFunctionWrapHandler,
    ) -> Any:
        """
        Serialize a value if it's not expired weak reference.
        """
        try:
            with warnings.catch_warnings():
                warnings.filterwarnings(
                    "ignore", message="Pydantic serializer warnings"
                )
                return handler(value)
        except ReferenceError:
            return None
        except ValueError as exc:
            if not str(exc).startswith("Circular reference"):
                raise exc
            return {value.ormar_config.pkname: value.pk} if value else None

        Serialize a value if it's not expired weak reference.
        
ormar/models/metaclass.py