Skip to content

Entity Id Modification Error

entity_id_modification_error

Module defining the EntityIdModificationError exception.

EntityIdModificationError

Bases: Error[dict[str, object]]

Raised when there is an attempt to modify an entity's identifier after it has been set.

Source code in src/forging_blocks/domain/errors/entity_id_modification_error.py
class EntityIdModificationError(Error[dict[str, object]]):
    """Raised when there is an attempt to modify an entity's identifier after it has been set."""

    def __init__(self, class_name: str, attribute_name: str, current_value: object) -> None:
        """Initialise the error with the class, attribute, and current value.

        Args:
            class_name: Name of the class whose identifier was targeted.
            attribute_name: Name of the attribute that was being modified.
            current_value: The current (immutable) value of the identifier.
        """
        message = ErrorMessage(
            f"Cannot modify '{attribute_name}' of {class_name} once set "
            f"(current value={current_value!r})."
        )
        metadata = ErrorMetadata[dict[str, object]](
            {
                "class_name": class_name,
                "attribute_name": attribute_name,
                "current_value": current_value,
            }
        )
        super().__init__(message, metadata)

__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
Source code in src/forging_blocks/domain/errors/entity_id_modification_error.py
def __init__(self, class_name: str, attribute_name: str, current_value: object) -> None:
    """Initialise the error with the class, attribute, and current value.

    Args:
        class_name: Name of the class whose identifier was targeted.
        attribute_name: Name of the attribute that was being modified.
        current_value: The current (immutable) value of the identifier.
    """
    message = ErrorMessage(
        f"Cannot modify '{attribute_name}' of {class_name} once set "
        f"(current value={current_value!r})."
    )
    metadata = ErrorMetadata[dict[str, object]](
        {
            "class_name": class_name,
            "attribute_name": attribute_name,
            "current_value": current_value,
        }
    )
    super().__init__(message, metadata)