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

Ensure that null is not returned as the item when creating an imported fact-check with original media in the GraphQL API. #2153

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

caiosba
Copy link
Contributor

@caiosba caiosba commented Dec 13, 2024

Description

When handling existing media to determine whether the imported fact-check will be added to or appended to the existing media, there was a scenario where the media already contained a fact-check in the same language being imported. In that scenario, nil was being returned. This PR fixes the issue by ensuring that a new object is returned in such cases, allowing the validations to handle whether the object is persisted or fails.

Fixes: CV2-5804.

How has this been tested?

TDD. I added a unit test that was able to reproduce the issue.

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

…ported fact-check with original media in GraphQL API.

When handling an existing media to decide if the imported fact-check is going to be added or appended to the existing media, there is a case where the media already exists with a fact-check in the same language that is trying to be imported. That case was returning nil. This PR fixes it by making sure that the new object is returned in that case, and then let the validations take care of returning a persisted or failed object.

Fixes: CV2-5804.
@caiosba caiosba requested review from vasconsaurus and melsawy and removed request for DGaffney, melsawy and jayjay-w December 13, 2024 13:57
@caiosba
Copy link
Contributor Author

caiosba commented Dec 13, 2024

@vasconsaurus can you please also review this since you worked on the feature CV2-5441?

@vasconsaurus
Copy link
Contributor

vasconsaurus commented Dec 13, 2024

@caiosba so in this case a new object is returned, but in the end it's creation will eventually fail since a media with the fact-check in the same language already exists?

EDIT: I understand why we need to do this. But for some reason I think it looks confusing. Maybe it's the name new_pm. But I don't know what is bugging me 😅

@caiosba
Copy link
Contributor Author

caiosba commented Dec 13, 2024

@vasconsaurus , an easier way to explain this, is: this method, at the model level, shouldn't know anything about the API where it's used. We can read its responsibility this way: "Given two items, choose which one to return given the existing and the new fact-check". Is it more clear put that way? :)

@caiosba caiosba merged commit b3f5756 into develop Dec 13, 2024
11 checks passed
@caiosba caiosba deleted the fix/CV2-5804-graphql-null-project-media-created branch December 13, 2024 19:08
caiosba added a commit that referenced this pull request Dec 21, 2024
…ported fact-check with original media in GraphQL API. (#2153)

When handling an existing media to decide if the imported fact-check is going to be added or appended to the existing media, there is a case where the media already exists with a fact-check in the same language that is trying to be imported. That case was returning nil. This PR fixes it by making sure that the new object is returned in that case, and then let the validations take care of returning a persisted or failed object.

Fixes: CV2-5804.
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