Entity Id Modification Error¶
entity_id_modification_error
¶
Error raised when code attempts to modify an entity's identity attribute.
Defines EntityIdModificationError, raised when an attempt is made to
change an entity's identity attribute (typically id) after it has already
been assigned. Once set, an entity's identity is immutable — modification
would break identity-based equality and hashing for aggregates.
Extends RuntimeErrorMixin and Error[MetadataValueType].
EntityIdModificationError
¶
Bases: RuntimeErrorMixin, Error[MetadataValueType]
Raised when there is an attempt to modify an entity's identifier after it has been set.
Once assigned, an entity's identifier is immutable. Changing the
id would break the stability guarantee required for hash-based
collections, identity comparisons, and reliable persistence. This
error fires at the __setattr__ interception point whenever a
re-assignment of the identity field is detected.
Example
Source code in src/forging_blocks/domain/errors/entity_id_modification_error.py
__init__(class_name: str, attribute_name: str, current_value: object) -> None
¶
Initialise the error with the class, attribute, and current value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
Name of the class whose identifier was targeted. |
required |
attribute_name
|
str
|
Name of the attribute that was being modified. |
required |
current_value
|
object
|
The current (immutable) value of the identifier. |
required |