-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
SDK - Components - Verify the object type when serializing primitive arguments #2272
SDK - Components - Verify the object type when serializing primitive arguments #2272
Conversation
…arguments Fixes an issue where if an input had a primitive type (e.g. `Integer`), you could pass anything to it (e.g. booleans, `ContainerOp`s, functions etc), because it just used `str` as serializer. Now the serializers chack the value type and raise error if the type is incorrect.
def _serialize_int(int_value: int) -> str: | ||
if isinstance(int_value, str): | ||
return int_value | ||
if not isinstance(int_value, int): |
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 think you can combine this two if by saying if not isinstance(int_value, int) and not isinstance(int_value, str)
?
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.
Similar for float/bool serializer
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 will work in this case, but it might not work for general serializer structure:
def serialize_some_type(value: SomeType):
if isinstance(value, str):
return value
if not isinstance(value, SomeType):
raise TypeError('Value "{}" has type "{}" instead of SomeType.'.format(str(value), str(type(value))))
return serialize(value)
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 find the existing code structure a little bit more readable with three clear cases.
Left a comment. Otherwise |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Ark-kun The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
…ubeflow#2272) * update versions for art-explainer to resolve several critical CVEs Signed-off-by: MessKon <messiskon@gmail.com> * update Dockerfile; use python:3.9-slim-bullseye instead Signed-off-by: MessKon <messiskon@gmail.com>
Fixes an issue where if an input had a primitive type (e.g.
Integer
), you could pass anything to it (e.g. booleans,ContainerOp
s, functions etc), because it just usedstr
as serializer. Now the serializers chack the value type and raise error if the type is incorrect.This change is