Skip to content
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

enhancement for empty values for list and str types #5560

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

imanjra
Copy link
Contributor

@imanjra imanjra commented Mar 10, 2025

What changes are proposed in this pull request?

This reverts some of the null coercion changes from #5375. Namely:

  • for string fields: empty "" values are NOT coerced to None if the default value of the field is ""
  • for list fields: empty [] values are NOT coerced to None if the default value of the field is []

How is this patch tested? If it is not, please explain why.

Using various operators with list/str type

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Introduced enhanced logic for value coercion based on user interaction and schema definitions.
    • Added new functions to determine when values should be coerced, improving data handling.
  • Refactor

    • Adjusted how input values are processed and stored, ensuring more predictable handling of data.

@imanjra imanjra requested a review from ritch March 10, 2025 01:18
Copy link
Contributor

coderabbitai bot commented Mar 10, 2025

Walkthrough

The changes reintroduce the coerceValue function in the SchemaIOComponent, now called with three parameters: path, value, and schema, instead of the previous two. The local version of coerceValue has been removed, consolidating its logic within the imported version. Additionally, two new functions, shouldCoerceValue and an updated coerceValue, have been added to handle value coercion based on user interaction and schema definitions, enhancing the control flow for processing values.

Changes

File Change Summary
app/.../SchemaIO/index.tsx Reintroduced coerceValue(path, value, schema) from utils, removed local coerceValue(value, schema), updated computedValue handling.
app/.../SchemaIO/utils/index.ts Added function shouldCoerceValue(path: string, schema: SchemaType) and export function coerceValue(path, value, schema) for value coercion logic.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant SchemaIOComponent
    participant StateManager
    participant CallbackHandler

    User->>SchemaIOComponent: Provide raw value
    SchemaIOComponent->>StateManager: set(raw value)
    SchemaIOComponent->>CallbackHandler: onPathChange(raw value)
Loading

Poem

I'm a little rabbit, hopping with glee,
Code changes so simple, as plain as can be.
No more weaving of values in a twist,
Just direct paths in a coding mist.
Cheers to the new flow, so fresh and free!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/packages/core/src/plugins/SchemaIO/index.tsx (1)

7-64: Consider adding TypeScript type annotations.

While the changes look good, I notice this component lacks TypeScript type annotations for props, function parameters, and return values. Adding proper type definitions would improve code maintainability and provide better IDE support.

-export function SchemaIOComponent(props) {
+export function SchemaIOComponent(props: {
+  onChange?: (state: any) => void;
+  onPathChange?: (path: string, value: any, schema: any, state: any) => void;
+  id: string;
+  shouldClearUseKeyStores?: boolean;
+  [key: string]: any;
+}) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8610cf4 and ee11385.

📒 Files selected for processing (1)
  • app/packages/core/src/plugins/SchemaIO/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Review the Typescript and React code for co...

**/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

  • app/packages/core/src/plugins/SchemaIO/index.tsx
🔇 Additional comments (3)
app/packages/core/src/plugins/SchemaIO/index.tsx (3)

25-25: Change that preserves original values looks good.

This change correctly removes value coercion, allowing empty strings and arrays to remain as-is rather than being converted to null. This aligns with the PR objective to revert the coercion behavior added in PR #5375.


28-28: Update to onPathChange parameter matches the value handling change.

This modification ensures that the raw value is consistently passed to all callbacks without coercion, maintaining consistency with the change on line 25. This change correctly supports the PR's goal of preserving empty values in their original form.


13-64:

❓ Verification inconclusive

Verify impact on dependent components.

Since this change affects how values are handled (no longer coercing empty strings/arrays to null), please ensure that all components receiving values from SchemaIOComponent can properly handle empty values instead of null values.


🏁 Script executed:

#!/bin/bash
# Search for components that consume SchemaIOComponent's output
# Look for references to onPathChange or onChange to find consumers
rg -A 10 -B 5 '<SchemaIOComponent' --type tsx

Length of output: 75


Below is a revised review comment that highlights the need for manual verification due to issues with our automated search:

Verify Handling of Empty Values in Consumers
Since the change now passes empty strings/arrays rather than coercing them to null, please manually verify that all components consuming output from SchemaIOComponent correctly handle these empty values. In our attempt to automatically locate dependent components (using an rg search for '<SchemaIOComponent' in .tsx files) we encountered an error because tsx files weren’t recognized. It’s important to double-check that nothing elsewhere in the codebase relies on receiving null values for empty entries.

  • Action Items:
    • Manually review components that use onChange or onPathChange from SchemaIOComponent to ensure they handle empty (non-null) values correctly.
    • Confirm that any assumptions based on null values are updated accordingly.

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

@imanjra based on your comment here, it sounds like reverting this null coercion behavior fixes your concern here. Can we find another solution to your concern on #5529 than this?

For context- the null coercion change we introduced as part of #5375 was an intentional change. The motivation was that in this common syntax:

inputs.str("str_field", required=False)

the property defaults to None. However, in a dynamic form, if the user types something into str_field and then deletes it, the prop now takes value "". This is a common gotcha for plugin devs, as they don't realize that they need to handle both None and "" in their execute() method to handle the case of a user who decides they don't want to use an optional string field after all. In fact, many of the core plugins in fiftyone-plugins suffer from this bug today, which is why #5375 is so convenient; it fixed the bugs without needing to update the plugins themselves.

@imanjra
Copy link
Contributor Author

imanjra commented Mar 11, 2025

@brimoor Oh, I see. I will make some changes to support that scenario.

@imanjra imanjra force-pushed the bugfix/empty-value-bug branch from ee11385 to 49e4d16 Compare March 11, 2025 13:14
@imanjra imanjra changed the title remove coercing of empty values to None enhancement for empty values for list and str types Mar 11, 2025
@imanjra
Copy link
Contributor Author

imanjra commented Mar 11, 2025

Updated PR with new logic below:

Only coerce value to None if it was modified by user and if the default value are not empty ("" for str and [] for list)

@imanjra imanjra requested a review from brimoor March 11, 2025 13:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
app/packages/core/src/plugins/SchemaIO/utils/index.ts (1)

159-174: Missing TypeScript type annotations for parameters.

The function implementation is correct and aligns with the PR objectives, but lacks type annotations which is inconsistent with the rest of the codebase.

Consider adding type annotations:

-export function coerceValue(path, value, schema) {
+export function coerceValue(path: string, value: any, schema: SchemaType) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee11385 and 49e4d16.

📒 Files selected for processing (2)
  • app/packages/core/src/plugins/SchemaIO/index.tsx (2 hunks)
  • app/packages/core/src/plugins/SchemaIO/utils/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/packages/core/src/plugins/SchemaIO/index.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{ts,tsx}`: Review the Typescript and React code for co...

**/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

  • app/packages/core/src/plugins/SchemaIO/utils/index.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: e2e / test-e2e
  • GitHub Check: lint / eslint
🔇 Additional comments (2)
app/packages/core/src/plugins/SchemaIO/utils/index.ts (2)

12-12: Import added to support user interaction checks.

New import ensures the code can determine if a path has been modified by the user, which is essential for the new coercion logic.


133-157: New function to determine when coercion should occur.

This function implements the core logic described in the PR objectives, preventing coercion of empty values to null when:

  1. The path hasn't been modified by the user
  2. The default value is an empty array (for array type)
  3. The default value is an empty string (for string type)

This addresses the confusion mentioned in the PR objectives where operators might expect empty strings or arrays instead of null.

@brimoor
Copy link
Contributor

brimoor commented Mar 11, 2025

Only coerce value to None if it was modified by user and if the default value are not empty ("" for str and [] for list)

Clever! This address my comment 👍

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

The updated behavior sounds good to me 👍

Defer to @ritch for the code review part if @imanjra would like that

@imanjra imanjra merged commit 071dd71 into develop Mar 11, 2025
12 checks passed
@imanjra imanjra deleted the bugfix/empty-value-bug branch March 11, 2025 16:53
@coderabbitai coderabbitai bot mentioned this pull request Mar 11, 2025
7 tasks
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.

3 participants