diff --git a/CHANGELOG.md b/CHANGELOG.md index 318e340e7..25c5ad2d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. * Rename queue option `table` to `collection` * Replace queue option `expire` with `retry_after` +## [4.3.1] + +* Fix memory leak when filling nested fields using dot notation by @GromNaN in [#2962](https://github.com/mongodb/laravel-mongodb/pull/2962) + ## [4.3.0] - 2024-04-26 * New aggregation pipeline builder by @GromNaN in [#2738](https://github.com/mongodb/laravel-mongodb/pull/2738) diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index de5ddc3ea..5974e49e1 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -46,7 +46,6 @@ use function str_contains; use function str_starts_with; use function strcmp; -use function uniqid; use function var_export; /** @mixin Builder */ @@ -55,6 +54,8 @@ abstract class Model extends BaseModel use HybridRelations; use EmbedsRelations; + private const TEMPORARY_KEY = '__LARAVEL_TEMPORARY_KEY__'; + /** * The collection associated with the model. * @@ -271,12 +272,10 @@ public function setAttribute($key, $value) // Support keys in dot notation. if (str_contains($key, '.')) { // Store to a temporary key, then move data to the actual key - $uniqueKey = uniqid($key); - - parent::setAttribute($uniqueKey, $value); + parent::setAttribute(self::TEMPORARY_KEY, $value); - Arr::set($this->attributes, $key, $this->attributes[$uniqueKey] ?? null); - unset($this->attributes[$uniqueKey]); + Arr::set($this->attributes, $key, $this->attributes[self::TEMPORARY_KEY] ?? null); + unset($this->attributes[self::TEMPORARY_KEY]); return $this; }