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

Fix bug where schema notification errors are not triggered when custo… #1287

Draft
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

JoshuaSBrown
Copy link
Collaborator

@JoshuaSBrown JoshuaSBrown commented Feb 4, 2025

…m metadata is empty

PR Description

Fixes bug where schema notifications are not being triggered when custom metadata field has not been specified.

Tasks

  • - A description of the PR has been provided, and a diagram included if it is a new feature.
  • - Formatter has been run
  • - CHANGELOG comment has been added
  • - Labels have been assigned to the pr
  • - A reviwer has been added
  • - A user has been assigned to work on the pr
  • - If new feature a unit test has been added

Summary by Sourcery

Bug Fixes:

  • Fix a bug where schema notification errors were not triggered when custom metadata was empty.

Copy link

sourcery-ai bot commented Feb 4, 2025

Reviewer's Guide by Sourcery

The pull request fixes a bug where schema notifications were not triggered when a custom metadata field was not specified. The fix ensures that empty curly braces are set as the default value for the metadata field, which triggers the schema validation errors.

Sequence diagram for record creation with metadata validation

sequenceDiagram
    participant Client
    participant DataRouter
    participant SchemaValidator

    Client->>DataRouter: Create record (no metadata)
    activate DataRouter
    Note right of DataRouter: Set empty metadata {}
    DataRouter->>SchemaValidator: Validate record
    activate SchemaValidator
    SchemaValidator-->>DataRouter: Return validation result
    deactivate SchemaValidator
    alt validation fails
        DataRouter-->>Client: Return error
    else validation passes
        DataRouter-->>Client: Return success
    end
    deactivate DataRouter
Loading

File-Level Changes

Change Details Files
Set default value for custom metadata to trigger schema validation.
  • Added a condition to check if the record.md exists.
  • If record.md does not exist, set obj.md to "{}".
core/database/foxx/api/data_router.js

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@JoshuaSBrown JoshuaSBrown added the Type: Bug Something isn't working label Feb 4, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @JoshuaSBrown - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The empty metadata should be set as an empty object ({}) rather than a string ('{}') to maintain type consistency and prevent potential issues with code expecting an object.
  • Consider adding a unit test to verify this behavior and prevent future regressions.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@@ -557,12 +557,17 @@ export function show(a_mode, a_data, a_parent, a_upd_perms, a_cb) {
$("#sch_id", frame).val(a_data.schId);
}

var md;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move away from using var, instead we can use let

https://www.geeksforgeeks.org/difference-between-var-and-let-in-javascript/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: md is not reallt descriptive enough. I can't arrive at metadata. I think of a medium t-shirt 👕

Comment on lines +563 to +564
} else {
md = {}; // Set empty metadata to an empty JSON object
Copy link
Collaborator

Choose a reason for hiding this comment

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

While I apprecaite the comment on setting the metadata object to blank, maybe we can comment what the:

                    var md = JSON.parse(a_data.metadata);
                    var txt = JSON.stringify(md, null, 4);
                    jsoned.setValue(txt, -1);

logic is doing and why.

@@ -99,9 +99,14 @@ function recordCreate(client, record, result) {
}
}

// If no custom metadata is provided by the user empty curly braces should
// be set so as to trigger schema validation errors.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Empty curly braces 👁️👄👁️

So if no custom metadata exists, we trigger schema validation with an empty object

@JoshuaSBrown JoshuaSBrown marked this pull request as draft February 5, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants