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

test(prisma): adjust test to validate upsert with id #1446

Closed
wants to merge 3 commits into from

Conversation

steebchen
Copy link
Owner

@steebchen steebchen commented Jan 13, 2025

Summary by CodeRabbit

  • Tests
    • Updated upsert test case to explicitly set ID during update operation
    • Modified expected test output to verify correct views count increment

Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request modifies the TestUpsert function in the upsert_test.go file. The change involves adding a new line Post.ID.Set("upsert") to the update method call in the second test case. This modification appears to explicitly set the ID during the upsert operation and updates the expected test output to reflect a change in the views count from 0 to 1.

Changes

File Change Summary
test/features/upsert/upsert_test.go Added Post.ID.Set("upsert") to the update method call in the second test case

The changes are minimal and focused on adjusting the test case's setup and expected behavior for the upsert operation.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 710ffee and 7fe9a9f.

📒 Files selected for processing (1)
  • test/features/upsert/upsert_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: integration-macos
  • GitHub Check: integration-windows
  • GitHub Check: lint
  • GitHub Check: test
🔇 Additional comments (1)
test/features/upsert/upsert_test.go (1)

70-70: Verify the necessity of setting ID in update.

Setting the ID in the update clause seems redundant since:

  1. The ID is already specified in the where clause (Post.ID.Equals("upsert"))
  2. The same ID is set in the create clause
  3. IDs typically shouldn't change during updates

Is this testing a specific edge case where ID handling during upsert needs validation? If not, consider removing this line.

Let's verify if there are any specific requirements or issues around ID handling during upsert:

✅ Verification successful

The ID setting in update follows the current upsert pattern.

While setting the ID in the update clause appears redundant, it follows the current pattern where fields need to be explicitly declared in both create and update clauses (see issue #489). This is a known limitation being tracked for improvement.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related tests or issues about ID handling in upsert
rg -g '!vendor' -l 'UpsertOne.*ID.*Set' .

# Search for any GitHub issues mentioning upsert ID handling
gh issue list --search "upsert ID in:title,body"

Length of output: 211


Script:

#!/bin/bash
# Get the content of issue #489
gh issue view 489

# Get the complete test context
cat test/features/upsert/upsert_test.go

Length of output: 3749

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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. (Beta)
  • @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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@ynden
Copy link
Contributor

ynden commented Jan 13, 2025

@steebchen Strange enough, it works on CI, but not on my side. This is what I get when I execute the test:
image

@steebchen
Copy link
Owner Author

steebchen commented Jan 13, 2025

yeah that's why I opened the PR to check if that's the case, I'm not sure why there is a diff; although the version is maybe too broadly defined in the compose.yml; however if there is really a breaking change it should also affect CI 🤷 actually it looks more like a prisma issue, which is also weird as the version is hardcoded

@ynden
Copy link
Contributor

ynden commented Jan 13, 2025

@steebchen Tests were run again, we do now have that issue with mongo in CI as well.

@steebchen
Copy link
Owner Author

Ah yah that explains a lot. Was the same CI issue I mentioned.

For the actual MongoDB issue, I think the Prisma engine just doesn't accept; maybe this is also a MongoBD restriction. I see in the docs that they say to use $set, which is also why there is some extra code for MongoDB in the .Update.

We would need to do more research I guess; alternatively we add the CreateOrUpdate() function only for SQL-like databases.

@ynden
Copy link
Contributor

ynden commented Jan 14, 2025

Ah yah that explains a lot. Was the same CI issue I mentioned.

For the actual MongoDB issue, I think the Prisma engine just doesn't accept; maybe this is also a MongoBD restriction. I see in the docs that they say to use $set, which is also why there is some extra code for MongoDB in the .Update.

We would need to do more research I guess; alternatively we add the CreateOrUpdate() function only for SQL-like databases.

Yeah you are right! I used the same schema, but using the prisma-client-js, and tried to do an upsert:
image

As we can see, I couldn't specify the id property in the update function. Which means this is forbidden even for other databases.

The following Go code shouldn't compile then:

actual, err := client.Post.UpsertOne(
	Post.ID.Equals("upsert"),
).Create(
	Post.Title.Set("title"),
	Post.Views.Set(0),
	Post.ID.Set("upsert"),
).Update(
	Post.Title.Set("title"),
	Post.Views.Increment(1),
	Post.ID.Set("random_id"), // should throw an error
).Exec(ctx)

Based on that we can conclude a few things for the CreateOrUpdate function:

  1. since we'll have all parameters in it (even the id, because it could also be at create time), we should have a way to remove the id before passing the fields to the update operation
  2. The Update function of theUpsertOne shouldn't compile when trying to modify an id

But down the line, CreateOrUpdate will only be ready when we have the ability to remove a field, or as you said, we could only allow for SQL like database for now.

What do you think?

@steebchen
Copy link
Owner Author

Yeah, I think for now it's fine to not have it, ideally it would not compile but I'm not sure if it's worth to refine the interfaces as it always adds more complexity.

For the CreateOrUpdate in the other PR, the tricky thing is that the ID field may have any name, so we would need to filter out keys which we could get from the schema but I'm also not sure if that's worth the effort.

@ynden
Copy link
Contributor

ynden commented Jan 16, 2025

I guess we can close this pull request then, since we now know that having an id in update is considered an error.

@steebchen
Copy link
Owner Author

yep indeed. feel free to open another PR for the CreateOrUpdate function.

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.

2 participants