Skip to content
Advertisement

validating parameter dictionaries before insertion in datajoint schema

We’d like to enforce parameter checking before people can insert into a schema as shown below, but the code below doesn’t work.

Is there a way to implement pre-insertion parameter checking?

JavaScript

Advertisement

Answer

This is a great question that has come up many times for us.

Most likely the issue is either that you are missing the class’ self reference or that you are missing the case where the key is passed in as a keyword argument (we are actually expecting it as a row instead).

I’ll demonstrate a simple example that hopefully can illustrate how to inject your validation code which you can tweak to perform as you’re intending above.

Suppose, we want to track filepaths within a dj.Manual table but I’d like to validate that only filepaths with a certain extension are inserted.

As you’ve already discovered, we can achieve this through overloading like so:

JavaScript

P.S. Though this example is meant to illustrate the concept, there is actually a better way of doing the above if you are using MySQL8. There is a CHECK utility available from MySQL that allows simple validation that DataJoint will respect. If those conditions are met, you can simplify it to:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement