-
Notifications
You must be signed in to change notification settings - Fork 9
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
#186 - Add FunctionParameter model and reduce schema parsing #203
#186 - Add FunctionParameter model and reduce schema parsing #203
Conversation
116a2b0
to
45dde74
Compare
("json", "JSON"), | ||
] | ||
RETURN_TYPES = PARAMETER_TYPES[:] | ||
RETURN_TYPE_CHOICES = PARAMETER_TYPE_CHOICES[:] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely clear on why this is a separate thing from PARAMETER_TYPE_CHOICES
, but that's how it was before and I decided to just keep it (though I renamed it for consistency).
_load_dockerfile_template(dockerfile, workdir) | ||
# Need to validate the potentially new function schema, but | ||
# don't save it until the build has finished. | ||
functions, function_parameters = _create_functions_from_definition( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This got bumped outside of the try block since:
- The exceptions being handled didn't seem like they could be raised by the lines here.
- The linter was rightfully complaining later on that technically
functions
could be unset.
package.image_name = image_name | ||
package.save() | ||
|
||
_delete_removed_function_parameters(function_parameters, package) | ||
_deactivate_removed_functions(function_definitions, package) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized this deactivate_removed_functions
call was in the wrong spot before, so I fixed that here.
"boolean": (BooleanField, None), | ||
"date": (DateField, HTMLDateInput), | ||
"date-time": ( | ||
PARAMETER_TYPE.INTEGER: (IntegerField, None), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know one of the complaints has been that there are multiple mappings to go update when we add a parameter type. I don't know that we can get it down to only 1 place, since in a case like this it's a mapping that's hyper specific to the TaskParameterForm. I think having the constants defined at least makes it a little less error prone.
I was testing and accidentally deleted part of a function and left the parameters section. The package.yaml ended up with two parameter sections:
I don't know if this was a feature before the refactor, but if we can catch this misconfiguration that'd be good thing. I'd error on multiple parameter definitions. |
We unfortunately cannot detect this particular error, since the library we're using (pyyaml) merges duplicate keys rather than throwing an error. This goes against the yaml spec, but it seems like they've never reached consensus on how to fix it. See discussions here and here. |
Closes #186
This switches the
Function
model to having its parameter definitions stored in a new modelFunctionParameter
, rather than through the pre-generatedschema
. The reasons for doing this are:Function
andWorkflow
consistent in their parameter handlingThe main changes that are happening here:
FunctionParameter
model now exists. It andWorkflowParameter
share a common base, so those two models and the base model now live incore/models/parameter.py
.FunctionParameter
instances rather than generating a pydantic schema.TaskParameterForm
now uses the info from theFunctionParameter
instances to construct the form, rather than relying on the schema.core/utils/parameter.py
(not to be confused with the now deletedparameters.py
) that is the home of all of the logic that deals with pydantic. Generating the schema and validating parameters against that schema all happen here. This file is also now the home of the single source of parameter type definitions. The various places that had defined their own parameter types now just import it from here.Other related changes:
core/utils/serialization.py
was no longer needed after these changes so that file is now gone. A much simpler helper method that just finds thejson
parameters from the database is included incore/utils/parameter.py
and used internally by t hevalidated_parameters
function there.FunctionParameter
instances.Test Instructions
WorkflowRun
and theFunctionParameter
removal during the build process work as expected.