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

Patching and DuplicatedFields #2984

Open
BravoTango86 opened this issue Feb 22, 2024 · 7 comments · May be fixed by #3617
Open

Patching and DuplicatedFields #2984

BravoTango86 opened this issue Feb 22, 2024 · 7 comments · May be fixed by #3617
Assignees
Labels
Milestone

Comments

@BravoTango86
Copy link

When undertaking a Patch operation, all duplicated fields are updated even if none have been amended.

Is it at all possible for for this to checked or suppressed?

@mysticmind
Copy link
Member

@BravoTango86 are you using plv8 based patching or the new inbuilt patching available in the latest beta?

It would help if you could share a repro/sample as well.

@BravoTango86
Copy link
Author

BravoTango86 commented Feb 24, 2024

Hi @mysticmind

Using the new patching function in v7 - the call to PatchOperation.applyUpdates is unconditional.

public record Test(Guid Id, [property:DuplicateField] string Key, string Value);
var record = new Test(CombGuidIdGeneration.NewGuid(), "test", "Test item");
lightweightSession.Insert(record);
lightweightSession.SaveChanges();
lightweightSession.Patch<Test>(record.Id).Set(r => r.Value, "Test");
lightweightSession.SaveChanges();

Results in:

select public.mt_insert_tests_test($1, $2, $3, $4, $5)
  : test
  : {"Id":"018dd875-efe0-41ab-b5b8-43b6fbd8c866","Key":"test","Value":"Test item"}
  : Demo.Demo+Test
  : 018dd875-efe0-41ab-b5b8-43b6fbd8c866
  : 018dd875-f41f-4d55-b0a3-bc746bdf6235
Persisted 0 updates in 16 ms, 1 inserts, and 0 deletions
update public.mt_doc_tests_test as d set data = public.mt_jsonb_patch(data, $1), mt_last_modified = (now() at time zone 'utc'), mt_version = $2 where d.id = $3
  : [{"type":"set","value":"Test","path":"Value"}]
  : 018dd875-f464-4a45-8548-a545c8d906ce
  : 018dd875-efe0-41ab-b5b8-43b6fbd8c866
update public.mt_doc_tests_test as d set key = data ->> 'Key' where d.id = $1
  : 018dd875-efe0-41ab-b5b8-43b6fbd8c866
Persisted 0 updates in 8 ms, 0 inserts, and 0 deletions

@mysticmind
Copy link
Member

mysticmind commented Feb 25, 2024

@BravoTango86 Thanks for the details. Looks like the plv8 implementation also has the same issue since that portion code is all the same in terms of implementation. I will troubleshoot and try to fix this.

@BravoTango86
Copy link
Author

Excellent, thank you!

@BravoTango86
Copy link
Author

Hi @mysticmind

Semi related though happy to submit as a separate issue - PatchFragment doesn't check whether last modified and version columns are disabled.

@mysticmind
Copy link
Member

Hi @mysticmind

Semi related though happy to submit as a separate issue - PatchFragment doesn't check whether last modified and version columns are disabled.

Please go ahead and raise it as a separate issue, will look to fix it.

@mysticmind
Copy link
Member

@BravoTango86 After a long hiatus, managed to fix this issue today, see PR #3617.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants