Skip to content

Add plugin hook for value validation#19

Open
MyPyDavid wants to merge 1 commit intomainfrom
codex/find-if-external-plugins-can-customize-error-messages
Open

Add plugin hook for value validation#19
MyPyDavid wants to merge 1 commit intomainfrom
codex/find-if-external-plugins-can-customize-error-messages

Conversation

@MyPyDavid
Copy link
Owner

Motivation

  • Allow third-party or local plugins to add custom validation logic for project values when they are saved.
  • Provide a configurable, pluggable extension point so validators can be registered via settings.

Description

  • Add a new setting PROJECT_VALUE_VALIDATORS in rdmo/core/settings.py to register validator plugins.
  • Introduce a ValueValidationPlugin base class in rdmo/projects/plugins.py with a validate_value(self, data, serializer) method.
  • Implement a ValuePluginValidator in rdmo/projects/validators.py that loads plugins with get_plugins('PROJECT_VALUE_VALIDATORS') and calls their validate_value methods.
  • Wire the ValuePluginValidator into the Value serializer validators in rdmo/projects/serializers/v1/__init__.py so plugin validators run during value serialization.

Testing

  • No automated tests were run.

Codex Task

@coveralls
Copy link

Pull Request Test Coverage Report for Build 20845183764

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 6 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 94.841%

Files with Coverage Reduction New Missed Lines %
projects/validators.py 2 96.84%
projects/serializers/v1/init.py 4 97.98%
Totals Coverage Status
Change from base Build 20342953613: -0.01%
Covered Lines: 22694
Relevant Lines: 23939

💛 - Coveralls

@MarcoReidelbach
Copy link

I tried this using a directly failing "validator" in MaRDMO

def validate_value(self, data, serializer):
raise serializers.ValidationError({
"text": ["These answers contradict each other."]
})

The validator is called correctly. In the Developer Tools of my Browser (Network Page) the message ("text") is also shown as response, but on the webpage its always just showing 'An unknown error occurred, please contact support'. Any idea?

I also tried Jochens idea using a pre_save handler, the result is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants