-
Notifications
You must be signed in to change notification settings - Fork 21
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
src/tarball: type conversion for version dict #437
Conversation
Tested OK on staging along with kernelci/kernelci-core#2382 and #425:
|
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.
Some comments:
First: if this is urgent because we need things running and not crashing, consider this approved and go ahead with the merge.
Second: these functions and parts of tarball.py in general could (and should) be dramatically refactored sometime. The problem with this patch is that you're leaking specific information about the model definition (in this case, that the type of those three fields should be an integer) into the client code. This means that if any of those fields ever change in the model we'll likely need to update this code as well.
Proposed solutions:
- move this model-specific type conversion as close to the model definition as possible. That is, at least in a kernelci-core lib function or, if possible, in the model class itself (although I don't think we're capable of that without a massive refactoring)
- consider turning these fields into strings, because why not? I know you went through the trouble of enabling strict pydantic checks specifically to allow ints but, why do we want ints in the first place? A good rule of thumb is that if we'll need to make any arithmetic with these, then we want them as numbers. If not, then we're ok with storing strings for everything and that'll save us some headaches.
Then there's the tarball.py and build.py refactorings (why do we have git_describe
and git_describe_verbose
? why not a single function for that? why does tarball.py use both for essentially the same thing? But these have nothing to do with this PR.
I suspect we might have filters based on version, probably making "data.kernel_revision.version.version > 6" is convinient... but this is a bit far fetching. |
True, user querying and filtering can make some use of this. |
I liked this idea. Yes, we already have some model-specific functions in
Then what is the purpose of having different field types? In addition to the use case that Denys pointed out, another problem will be any string value can be inserted in the version information and not just numbers as strings if we define the fields as strings. And that will cause other issues in the |
My thought was not about field types in general, but about the usefulness of dividing the kernel version string into individual typed fields, when a single string + an unpacking function would do for most cases. But, as Denys pointed out (and I agree), it'll be necessary if we want to filter or query by version number and operate on that (eg. search test results for kernels higher than a certain version, etc). |
As the API has enforced strict int data type for some of the version information fields, data type cast is required to make sure `int` fields are not sent off as `str` fields. Otherwise, the below error will be encountered: ``` kernelci-pipeline-tarball | 02/16/2024 07:15:59 AM UTC [ERROR] 2 validation errors for Checkout kernelci-pipeline-tarball | data -> kernel_revision -> version -> version kernelci-pipeline-tarball | value is not a valid integer (type=type_error.integer) kernelci-pipeline-tarball | data -> kernel_revision -> version -> patchlevel kernelci-pipeline-tarball | value is not a valid integer (type=type_error.integer) ``` Use API helper function for translation of version fields before submitting them to the API. Signed-off-by: Jeny Sadadia <jeny.sadadia@collabora.com>
6936515
to
ca4dfdd
Compare
Closing this as an alternate solution got merged. |
Depends on kernelci/kernelci-core#2382
As the API has enforced strict int data type for some of the version information fields, data type cast is required to make sure
int
fields are not sent off asstr
fields. Otherwise, the below error will be encountered: