artsy / positron

Positron is Artsy Writer or the editorial tool and API for Artsy.
MIT License
85 stars 42 forks source link

fix: articles and sessions save functions #3134

Closed mc-jones closed 5 months ago

mc-jones commented 5 months ago

This PR patches #3131 after testing on staging exposed a regression.

Problem

Users were unable to create or edit articles as a bug in the save logic meant that documents were being persisted with a _id of null when upserted.

Solution

Change the implementation of the articles and sessions' save method to check for an existing _id of the object to be persisted, use updateOne when it exists, and use insertOne (instead of an upsert on a updateOne) when it doesn't.

Considerations

If I am missing something in the code, or using bad assumptions, then please let me know.

codecov[bot] commented 5 months ago

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (fada331) 83.6% compared to head (5246774) 83.5%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #3134 +/- ## ======================================= - Coverage 83.6% 83.5% -0.1% ======================================= Files 197 197 Lines 5383 5388 +5 Branches 977 977 ======================================= - Hits 4501 4500 -1 - Misses 630 635 +5 - Partials 252 253 +1 ```