Skip to content

Commit 4756f22

Browse files
committed
Force include optional attributes on upsert
1 parent 9ff077c commit 4756f22

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Database/Database.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4916,8 +4916,8 @@ public function createOrUpdateDocumentsWithIncrease(
49164916
$batchSize = \min(Database::INSERT_BATCH_SIZE, \max(1, $batchSize));
49174917
$collection = $this->silent(fn () => $this->getCollection($collection));
49184918
$documentSecurity = $collection->getAttribute('documentSecurity', false);
4919+
$collectionAttributes = $collection->getAttribute('attributes', []);
49194920
$time = DateTime::now();
4920-
49214921
$created = 0;
49224922
$updated = 0;
49234923

@@ -4980,6 +4980,14 @@ public function createOrUpdateDocumentsWithIncrease(
49804980
if ($old->isEmpty()) {
49814981
$createdAt = $document->getCreatedAt();
49824982
$document->setAttribute('$createdAt', empty($createdAt) || !$this->preserveDates ? $time : $createdAt);
4983+
4984+
// Force matching optional parameter sets
4985+
// Doesn't use decode as that intentionally skips null defaults to reduce payload size
4986+
foreach ($collectionAttributes as $attr) {
4987+
if (!$attr->getAttribute('required') && !$document->isSet($attr['$id'])) {
4988+
$document->setAttribute($attr['$id'], $attr['default'] ?? null);
4989+
}
4990+
}
49834991
} else {
49844992
$document['$createdAt'] = $old->getCreatedAt();
49854993
}

0 commit comments

Comments
 (0)