diff --git a/authentik/blueprints/v1/common.py b/authentik/blueprints/v1/common.py index 6d41ac988..997fecc6f 100644 --- a/authentik/blueprints/v1/common.py +++ b/authentik/blueprints/v1/common.py @@ -584,12 +584,17 @@ class EntryInvalidError(SentryIgnoredException): entry_model: Optional[str] entry_id: Optional[str] validation_error: Optional[ValidationError] + serializer: Optional[Serializer] = None - def __init__(self, *args: object, validation_error: Optional[ValidationError] = None) -> None: + def __init__( + self, *args: object, validation_error: Optional[ValidationError] = None, **kwargs + ) -> None: super().__init__(*args) self.entry_model = None self.entry_id = None self.validation_error = validation_error + for key, value in kwargs.items(): + setattr(self, key, value) @staticmethod def from_entry( diff --git a/authentik/blueprints/v1/importer.py b/authentik/blueprints/v1/importer.py index f2191548e..eb4942958 100644 --- a/authentik/blueprints/v1/importer.py +++ b/authentik/blueprints/v1/importer.py @@ -255,7 +255,10 @@ class Importer: try: full_data = self.__update_pks_for_attrs(entry.get_attrs(self._import)) except ValueError as exc: - raise EntryInvalidError.from_entry(exc, entry) from exc + raise EntryInvalidError.from_entry( + exc, + entry, + ) from exc always_merger.merge(full_data, updated_identifiers) serializer_kwargs["data"] = full_data @@ -272,6 +275,7 @@ class Importer: f"Serializer errors {serializer.errors}", validation_error=exc, entry=entry, + serializer=serializer, ) from exc return serializer @@ -300,16 +304,18 @@ class Importer: ) return False # Validate each single entry + serializer = None try: serializer = self._validate_single(entry) except EntryInvalidError as exc: # For deleting objects we don't need the serializer to be valid if entry.get_state(self._import) == BlueprintEntryDesiredState.ABSENT: - continue - self.logger.warning(f"entry invalid: {exc}", entry=entry, error=exc) - if raise_errors: - raise exc - return False + serializer = exc.serializer + else: + self.logger.warning(f"entry invalid: {exc}", entry=entry, error=exc) + if raise_errors: + raise exc + return False if not serializer: continue diff --git a/authentik/blueprints/v1/tasks.py b/authentik/blueprints/v1/tasks.py index 194a01748..8ff86c996 100644 --- a/authentik/blueprints/v1/tasks.py +++ b/authentik/blueprints/v1/tasks.py @@ -82,7 +82,7 @@ class BlueprintEventHandler(FileSystemEventHandler): path = Path(event.src_path) root = Path(CONFIG.get("blueprints_dir")).absolute() rel_path = str(path.relative_to(root)) - for instance in BlueprintInstance.objects.filter(path=rel_path): + for instance in BlueprintInstance.objects.filter(path=rel_path, enabled=True): LOGGER.debug("modified blueprint file, starting apply", instance=instance) apply_blueprint.delay(instance.pk.hex)