fix: stop patches from resetting dataset size fields to 0 - #2862
Merged
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="test/DatasetCustom.js" line_range="625-634" />
<code_context>
+ });
+ });
+
+ it("0910: explicitly sets packedSize and numberOfFilesArchived", async () => {
+ return request(appUrl)
+ .patch(`/api/v3/Datasets/${encodeURIComponent(sizeFieldsPid)}`)
+ .send({ packedSize: 6789, numberOfFilesArchived: 3 })
+ .set("Accept", "application/json")
+ .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
+ .expect(TestData.SuccessfulPatchStatusCode)
+ .expect("Content-Type", /json/)
+ .then((res) => {
+ res.body.should.have.property("packedSize").and.equal(6789);
+ res.body.should.have.property("numberOfFilesArchived").and.equal(3);
+ });
+ });
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding a test where only a subset of size-related fields is patched to ensure the others are preserved.
Current tests cover patching an unrelated field when all four size-related fields are initially set, but not patching only one or two of those fields. To guard against regressions from the previous defaulting-to-0 behavior, please add a test that patches only one field (e.g., `size`) and asserts that `packedSize`, `numberOfFiles`, and `numberOfFilesArchived` remain unchanged.
Suggested implementation:
```javascript
it("0900: adds a new custom dataset with explicit size and numberOfFiles", async () => {
const customDatasetWithSize = {
...TestData.CustomDatasetCorrect,
size: 12345,
```
```javascript
.expect(TestData.EntryCreatedStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("pid").and.be.a("string");
res.body.should.have.property("size").and.equal(12345);
res.body.should.have.property("numberOfFiles").and.equal(6);
sizeFieldsPid = res.body["pid"];
});
});
it("0910: explicitly sets packedSize and numberOfFilesArchived", async () => {
return request(appUrl)
.patch(`/api/v3/Datasets/${encodeURIComponent(sizeFieldsPid)}`)
.send({ packedSize: 6789, numberOfFilesArchived: 3 })
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.SuccessfulPatchStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("packedSize").and.equal(6789);
res.body.should.have.property("numberOfFilesArchived").and.equal(3);
});
});
it("0920: patching only size preserves other size-related fields", async () => {
// first, ensure all four size-related fields are explicitly set
await request(appUrl)
.patch(`/api/v3/Datasets/${encodeURIComponent(sizeFieldsPid)}`)
.send({
size: 12345,
packedSize: 6789,
numberOfFiles: 6,
numberOfFilesArchived: 3,
})
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.SuccessfulPatchStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("size").and.equal(12345);
res.body.should.have.property("packedSize").and.equal(6789);
res.body.should.have.property("numberOfFiles").and.equal(6);
res.body.should.have.property("numberOfFilesArchived").and.equal(3);
});
// then, patch only `size` and ensure the other fields remain unchanged
return request(appUrl)
.patch(`/api/v3/Datasets/${encodeURIComponent(sizeFieldsPid)}`)
.send({ size: 54321 })
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenAdminIngestor}` })
.expect(TestData.SuccessfulPatchStatusCode)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("size").and.equal(54321);
res.body.should.have.property("packedSize").and.equal(6789);
res.body.should.have.property("numberOfFiles").and.equal(6);
res.body.should.have.property("numberOfFilesArchived").and.equal(3);
});
});
});
```
If the surrounding describe block already has setup/teardown that manipulates `sizeFieldsPid` or size-related fields, you may want to adjust the initial patch in test `0920` to align with the values established there (e.g., using different starting values or reusing ones from previous tests). Also ensure that `accessTokenAdminIngestor`, `appUrl`, and `TestData.SuccessfulPatchStatusCode` are defined in the test file or shared test helpers as they are used consistently across existing tests.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
fpotier
reviewed
Jul 30, 2026
fpotier
left a comment
Member
There was a problem hiding this comment.
Does the size update mechanism handle null?
For instance if I create a dataset without specifying a size and then add an origdatablock (I believe this triggers a recompute of the size)
Would be a breaking change but since the backend does the book keeping for size, packedSize etc. would it make sense to remove/ignore them from create/update dtos?
Member
Author
|
good question, let me add a test for that and we see that |
fpotier
approved these changes
Jul 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Having explicit defaults makes plainToInstance attach fields with 0s even when missing in the patch payload. This then updates the document's values in mongo to 0 even when missing in the payload
Raw and derived datasets have dedicated DTOs so this fixes the bug for other types
Tests included
Documentation
official documentation info
Summary by Sourcery
Prevent dataset size-related fields from being unintentionally reset when applying partial updates to v3 custom datasets.
Bug Fixes:
Tests: