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

Need to validate data when doing Table.update #33

Open
csdev opened this issue Jun 17, 2014 · 9 comments
Open

Need to validate data when doing Table.update #33

csdev opened this issue Jun 17, 2014 · 9 comments
Labels

Comments

@csdev
Copy link

csdev commented Jun 17, 2014

The Table.create method uses joi to check that all of the supplied data is valid before attempting to serialize it and write it to the database (table.js line 116). However, Table.update does not do any data validation. This can result in invalid data being saved to the db. It can also cause a crash since some of the serializer code assumes that it is working with valid data. (For example, if the user performs an update with an invalid Date, a later call to Date.toISOString will raise an uncaught error.)

@ryanfitz
Copy link
Owner

I agree that we should validate this data. The reason data is currently only validated during create is because during update you can pass different pieces of data which are completely valid during update, but would not be valid when creating an initial record. Such as partial updates, removing params from dynamodb, and adding items to Sets.

I'm sure there is a good solution for this, but I want to be careful that we don't over complicate things and potentially make it difficult to fully utilize the feature DynamoDB offers

@viniciuskneves
Copy link

@ryanfitz I've got on similar issue this week and some coworkers have faced it too in the past. I've two different suggestions that could be implemented (I could open the PR if you prefer and don't have time to it). First one would be add an option like 'updateValidation' (false as default) and it would be able validation before update. The problem that I see on this feature is that it is a little bit intrusive.
The second one would be able to return the object schema and them it would be able to validate it before performing an update whenever the developer feels it is necessary.

Would like to know your opinion. I'm adapting (not modifying the lib) the second solution over here as we've faced some problems...

@avtaniket
Copy link

@viniciuskneves Yes, this issue need to be handled, an record update is important operation as much as create, so we must validate data before update.

We should have separate mechanism to validate data on update eg. updateValidations() or validateOnUpdate(true) during schema.

@Alex0007
Copy link

validation mechanism in vogels is incomplete without this

+1 for this feature

@speedster-kiev
Copy link

+1 for feature

1 similar comment
@andyday
Copy link

andyday commented Mar 15, 2016

+1 for feature

@sjungwirth
Copy link

sjungwirth commented Aug 12, 2016

+1
I would also like to do on demand validation, before making the create request, which currently seems impossible due to table/schema being private.

@AaronHarris
Copy link

@sjungwirth I finally found you can access the table/schema by calling model.scan(), which returns an object with the table, which contains the schema object, which you can call validate. It's hacky but it seems the easiest way to access the object.

@sjungwirth
Copy link

@AaronHarris this is really helpful, thank you. While looking into what you said it looks like there is a reference to table on model instances as well. So it looks like either of these will work:

myModelInstance.table.schema.validate(myModelInstance) or MyModel.scan().table.schema.validate(myDataOrModelInstanceToValidate)

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

No branches or pull requests

9 participants