Skip to content

fix: avoid using HasField on scalar primitives in DataConverter#985

Merged
patricklundquist merged 3 commits intomasterfrom
fix-data-scalar-fields-hasfield-9151022936464392563
Mar 13, 2026
Merged

fix: avoid using HasField on scalar primitives in DataConverter#985
patricklundquist merged 3 commits intomasterfrom
fix-data-scalar-fields-hasfield-9151022936464392563

Conversation

@patricklundquist
Copy link
Copy Markdown
Contributor

In proto3, standard scalar fields like string_value or int_value do not support HasField(). Calling HasField() on these fields raises a ValueError. This commit updates clarifai/runners/utils/data_utils.py to evaluate the truthiness or explicit default values of these scalar fields instead of using HasField(). HasField() calls were retained when checking pb_value in Param.from_proto because pb_value is google.protobuf.Value and these variants are part of a oneof.

In proto3, standard scalar fields like string_value or int_value do not support `HasField()`. Calling `HasField()` on these fields raises a ValueError. This commit updates `clarifai/runners/utils/data_utils.py` to evaluate the truthiness or explicit default values of these scalar fields instead of using `HasField()`. `HasField()` calls were retained when checking `pb_value` in `Param.from_proto` because `pb_value` is `google.protobuf.Value` and these variants are part of a oneof.

Co-authored-by: patricklundquist <1460278+patricklundquist@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the runner-side DataConverter utilities to avoid calling HasField() on proto3 scalar primitives (which raises ValueError), while retaining HasField() usage where fields are part of a oneof (google.protobuf.Value).

Changes:

  • Remove HasField() checks for scalar primitive fields (e.g., string_value) and switch to value/default comparisons.
  • Update is_old_format() to detect “old format” using scalar default checks instead of HasField() for those scalars.
  • Remove redundant in-function json imports (module-level import json is used).

Comment thread clarifai/runners/utils/data_utils.py Outdated
Comment thread clarifai/runners/utils/data_utils.py Outdated
@patricklundquist
Copy link
Copy Markdown
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 12, 2026

@patricklundquist I've opened a new pull request, #986, to work on those changes. Once the pull request is ready, I'll request review from you.

patricklundquist and others added 2 commits March 12, 2026 16:01
Added JSON import to handle default values in methods.
…it tests (#986)

* Initial plan

* refactor: extract _has_scalar_set helper and add is_old_format tests

Co-authored-by: patricklundquist <1460278+patricklundquist@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: patricklundquist <1460278+patricklundquist@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Health
clarifai 45%
clarifai.cli 61%
clarifai.cli.templates 67%
clarifai.cli.templates.toolkits 100%
clarifai.client 65%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 69%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.rag 0%
clarifai.runners 52%
clarifai.runners.models 58%
clarifai.runners.pipeline_steps 39%
clarifai.runners.pipelines 72%
clarifai.runners.utils 62%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 58%
clarifai.utils 65%
clarifai.utils.evaluation 16%
clarifai.workflows 95%
Summary 60% (11356 / 18956)

Minimum allowed line rate is 50%

@patricklundquist patricklundquist merged commit c268801 into master Mar 13, 2026
15 of 35 checks passed
@patricklundquist patricklundquist deleted the fix-data-scalar-fields-hasfield-9151022936464392563 branch March 13, 2026 19:08
@ackizilkale ackizilkale mentioned this pull request Mar 18, 2026
2 tasks
Copilot AI mentioned this pull request Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants