-
Notifications
You must be signed in to change notification settings - Fork 22
Feat/add metadata #1531
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
base: main
Are you sure you want to change the base?
Feat/add metadata #1531
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,6 +42,11 @@ internal DataElementChange(ChangeType type, DataType dataType, string contentTyp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ContentType = contentType; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The metadata of the data element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private List<KeyValueEntry>? _metadata = []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contradictory initialization logic. The field is declared nullable and initialized to an empty list, but line 100 uses lazy initialization ( Apply this diff for lazy initialization (recommended): - private List<KeyValueEntry>? _metadata = [];
+ private List<KeyValueEntry>? _metadata;Or apply this diff for eager initialization: - private List<KeyValueEntry>? _metadata = [];
+ private List<KeyValueEntry> _metadata = [];And remove line 100's null-coalescing: - _metadata ??= [];
- _metadata.Add(new KeyValueEntry { Key = key, Value = value });
+ _metadata.Add(new KeyValueEntry { Key = key, Value = value });
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The type of update: Create, Update or Delete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -67,6 +72,34 @@ internal DataElementChange(ChangeType type, DataType dataType, string contentTyp | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The contentType of an element in storage | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public string ContentType { get; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The metadata of the data element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal IReadOnlyCollection<KeyValueEntry>? Metadata => _metadata; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// If true, no more metadata can be added | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal bool Lock { get; set; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Add metadata to a created data element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public void AddMetadata(string key, string value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Type != ChangeType.Created) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new InvalidOperationException("Metadata can only be added to created data elements"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Lock) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw new InvalidOperationException("Metadata already locked"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _metadata ??= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _metadata.Add(new KeyValueEntry { Key = key, Value = value }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+89
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add parameter validation for key and value. The method lacks validation to ensure Apply this diff to add validation: public void AddMetadata(string key, string value)
{
+ ArgumentException.ThrowIfNullOrWhiteSpace(key);
+ ArgumentException.ThrowIfNullOrWhiteSpace(value);
+
if (Type != ChangeType.Created)
{
throw new InvalidOperationException("Metadata can only be added to created data elements");
}
if (Lock)
{
throw new InvalidOperationException("Metadata already locked");
}
_metadata ??= [];
_metadata.Add(new KeyValueEntry { Key = key, Value = value });
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Verify if metadata can be included in the initial Insert call.
The current implementation makes two sequential async calls when metadata is present:
InsertBinaryDatafollowed byUpdate. This introduces additional latency and a potential inconsistency if the Update fails (the data element is created but metadata is not persisted, yetLockis already set totrue).Run the following script to check if the
IDataClient.InsertBinaryDatamethod signature or overloads support metadata:If the API does not support metadata on creation, consider adding error handling:
if (change.Metadata is not null) { dataElement.Metadata = [.. change.Metadata]; - change.Lock = true; - await _dataClient.Update(Instance, dataElement); + try + { + await _dataClient.Update(Instance, dataElement); + change.Lock = true; + } + catch + { + // Metadata update failed; consider logging or cleanup + throw; + } }🏁 Script executed:
Length of output: 8577
Length of output: 310
Length of output: 2241
Move
change.Lock = trueafter the successfulUpdatecall.The
InsertBinaryDatamethod does not support a metadata parameter, so the two-call approach is necessary. However, settingchange.Lock = truebefore awaiting theUpdatecall (line 453) risks leaving the object in an inconsistent state if the update fails—the lock would be set while metadata persistence failed.Move the lock assignment after the successful update completes:
if (change.Metadata is not null) { dataElement.Metadata = [.. change.Metadata]; - change.Lock = true; - await _dataClient.Update(Instance, dataElement); + await _dataClient.Update(Instance, dataElement); + change.Lock = true; }📝 Committable suggestion
🤖 Prompt for AI Agents