MCPcopy
hub / github.com/ormar-orm/ormar / _emit_signal

Method _emit_signal

ormar/models/model.py:41–65  ·  view source on GitHub ↗

Emit a lifecycle signal on this model's SignalEmitter. When ``ormar_config.emit_parent_signals`` is True, the same signal is also dispatched on every concrete ormar ancestor in the MRO. Each emit uses ``sender=ancestor_cls`` so handlers registered with ``@pr

(self, name: str, **kwargs: Any)

Source from the content-addressed store, hash-verified

39 return row
40
41 async def _emit_signal(self, name: str, **kwargs: Any) -> None:
42 """
43 Emit a lifecycle signal on this model's SignalEmitter.
44
45 When ``ormar_config.emit_parent_signals`` is True, the same signal is
46 also dispatched on every concrete ormar ancestor in the MRO. Each
47 emit uses ``sender=ancestor_cls`` so handlers registered with
48 ``@pre_save(Parent)`` see the parent class as the sender.
49
50 :param name: signal name on the SignalEmitter (e.g. ``"pre_save"``).
51 :type name: str
52 :param kwargs: extra payload forwarded to receivers.
53 :type kwargs: Any
54 """
55 cls = type(self)
56 await getattr(self.ormar_config.signals, name).send(sender=cls, **kwargs)
57 if not self.ormar_config.emit_parent_signals:
58 return
59 seen = {id(self.ormar_config.signals)}
60 for ancestor in cls.__mro__[1:]:
61 cfg = getattr(ancestor, "ormar_config", None)
62 if cfg is None or cfg.abstract or id(cfg.signals) in seen:
63 continue
64 seen.add(id(cfg.signals))
65 await getattr(cfg.signals, name).send(sender=ancestor, **kwargs)
66
67 async def upsert(self: T, **kwargs: Any) -> T:
68 """

Callers 3

saveMethod · 0.95
updateMethod · 0.95
deleteMethod · 0.95

Calls 2

sendMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected