django-service-objects icon indicating copy to clipboard operation
django-service-objects copied to clipboard

Add support for validating None declared fields.

Open jackton1 opened this issue 5 years ago • 3 comments

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: ({...})'

jackton1 avatar Mar 04 '21 16:03 jackton1

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?

peterfarrell avatar Dec 19 '22 18:12 peterfarrell

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.

jackton1 avatar Dec 28 '22 04:12 jackton1

@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?

peterfarrell avatar Jan 06 '23 15:01 peterfarrell