fairdm.registry.exceptions#

Exceptions raised by the registry.

Module Contents#

API#

exception RegistryError[source]#

Bases: Exception

Base exception for all registry errors.

All registry-specific exceptions inherit from this class, allowing catching of all registry errors with a single except block.

Example: try: @register class BadConfig(ModelConfiguration): model = BadModel # Missing Sample/Measurement inheritance except RegistryError as e: logger.error(f”Registration failed: {e}”)

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception ConfigurationError(message: str, model: type[django.db.models.Model] | None = None, config_class: type | None = None)[source]#

Bases: fairdm.registry.exceptions.RegistryError

Invalid ModelConfiguration setup.

Raised when:

  • Model doesn’t inherit from Sample or Measurement

  • Required model attribute is missing

  • Custom class doesn’t inherit from expected base

  • Invalid configuration combination

The message is prefixed with the model’s or configuration class’s name when either is given.

Args: message: Error description. model: The Django model class, if known. config_class: The ModelConfiguration class, if known.

Example: raise ConfigurationError( “model attribute is required”, config_class=RockSampleConfig )

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception FieldValidationError(field_name: str, model: type[django.db.models.Model], attribute: str | None = None, suggestion: str | None = None, reason: str | None = None)[source]#

Bases: fairdm.registry.exceptions.RegistryError

A field name in a configuration does not resolve on the model.

The message names the four things a portal developer needs in order to fix it: the model, the attribute that declared the name, the name itself, and either a close match or the reason the path stopped resolving.

Args: field_name: The name or path that failed. model: The Django model it was declared against. attribute: The configuration attribute that declared it. suggestion: A comma-separated list of close matches, if any. reason: Why the path stopped resolving, where that is not a missing name.

Example: raise FieldValidationError( “loction”, RockSample, attribute=“fields”, suggestion=“location” ) # “Invalid field ‘loction’ in RockSample.fields: no such field on # RockSample. Did you mean: location?”

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception NotRegisteredError(model: type[models.Model] | str)[source]#

Bases: fairdm.registry.exceptions.RegistryError, KeyError

The configuration of a model that was never registered was requested.

Subclasses KeyError so that callers written against the registry’s earlier behaviour keep working, while the message names the model rather than repeating its label as a bare key.

Args: model: The model class, or its app_label.ModelName label.

Initialization

Initialize self. See help(type(self)) for accurate signature.

exception DuplicateRegistrationError(model: type[django.db.models.Model], original_location: str, new_location: str | None = None)[source]#

Bases: fairdm.registry.exceptions.RegistryError

Model registered multiple times.

Raised when attempting to register a model that’s already registered. Each model can only be registered once.

Args: model: The Django model class. original_location: Module path where the model was first registered. new_location: Module path of the duplicate registration attempt.

Example: raise DuplicateRegistrationError( RockSample, original_location=‘myapp.registry’, new_location=‘myapp.another_registry’ ) # “RockSample already registered at myapp.registry. Each model can only # be registered once. Attempted duplicate registration from # myapp.another_registry.”

Initialization

Initialize self. See help(type(self)) for accurate signature.