question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Single Item last field gets duplicated on Replace (When upsert: true and field names in Datastore are in camel case)

See original GitHub issue

Bug:

  • When replacing a field value on single item mode, the last field that gets updated duplicates itself in the DataStore file.

Replication:

public static class Program
{
    public static void Main(string[] args)
    {
        var entity = new Entity();
        
        for (int i = 1; i <= 2; i++)
        {
            // First to Update
            entity.DoesNotDuplicate = $"Updated {i} Times, Doesn't Duplicate";
                    
            // Last to Update
            entity.Duplicates = $"Updated {i} Times, Duplicates";
            Thread.Sleep(500);
        }
    }
    internal class Entity
    {
        private static readonly DataStore _dataStore = new DataStore("DuplicateBug.json");

        internal string? DoesNotDuplicate
        {
            get => _dataStore.GetItem(nameof(DoesNotDuplicate));
            set => _dataStore.ReplaceItem(nameof(DoesNotDuplicate), value, true);
        }

        internal string? Duplicates
        {
            get => _dataStore.GetItem(nameof(Duplicates));
            set => _dataStore.ReplaceItem(nameof(Duplicates), value, true);
        }
    }
}

Output:

{
  "doesNotDuplicate": "Updated 2 Times, Doesn't Duplicate",
  "duplicates": "Updated 1 Times, Duplicates",
  "duplicates": "Updated 2 Times, Duplicates"
}

Observation:

  • the doesNotDuplicate field is updated correctly, does not duplicate itself since it is the first field updated.
  • the duplicates field is not updated correctly, and duplicates itself instead.

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ttucommented, Jun 25, 2023
1reaction
ttucommented, Jun 23, 2023

Fixed in: #89

Fix will be in the next patch release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues · ttu/json-flatfile-datastore
Single Item last field gets duplicated on Replace (When upsert: true and field names in Datastore are in camel case) bug in progress....
Read more >
Why does upsert cause a DUPLICATE_VALUE error?
I have a custom object, with a Text Name (ID) field. When I upsert two records with identical Name/ID, but otherwise different values,...
Read more >
MongoDB inserting duplicate document within upsert
I was checking existing data within the DB and found several documents in which the fields that should be used to match in...
Read more >
arcgis.features module | ArcGIS API for Python
Used only when upsert is true. Used to skip inserts if the value is true. The default value is false. upsert_matching_field. Optional string....
Read more >
Strange Error: "A duplicate value was specified for field"
If you r trying to deploy metadata(Object information) from one Org to another, and the fields name are same you get this error....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found