Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for validating None declared fields. #65

Open
jackton1 opened this issue Mar 4, 2021 · 3 comments
Open

Add support for validating None declared fields. #65

jackton1 opened this issue Mar 4, 2021 · 3 comments

Comments

@jackton1
Copy link
Contributor

jackton1 commented Mar 4, 2021

The services shouldn't allow more fields than expected when calling execute

class MyService(Service):
	field_a = forms.CharField(...)

Call

MyService.execute({ 'field_y': 1, 'field_a'; 2 })

Expectations:
Raises an exception

'Invalid field provided "field_y": Please provide one of the following fields: ({...})'
@peterfarrell
Copy link
Contributor

The base Service object inherits from django.forms.BaseForm. Django Forms allow you pass anything to the data attribute of __init__ . Making this change likely breaks backwards compatibility as the Service object no longer behaves as expected.

@jackton1 What's the use case for things being more restrict? Base an additional attribute of Service called strict_inputs that defaults to False for backwards compatibility would be an acceptable PR?

@jackton1
Copy link
Contributor Author

jackton1 commented Dec 28, 2022

A common issue here has been running into a bug where the field key provided when invoking the service didn’t match the defined field name and there wasn’t any errors reported since the field wasn’t required.

@peterfarrell
Copy link
Contributor

@jackton1 makes sense - I think we'd have to add a new switch to indicate you wanted that behavior of strict inputs. Personally I know it would break some of the apps without it. How about a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants