{"record":{"id":"dc45a8ca1b2d6656","repo":"doctrine/orm","slug":"field-s-is-not-a-valid-field-of-the-entity-s","errorCode":null,"errorMessage":"Field \"%s\" is not a valid field of the entity \"%s\" in PreUpdateEventArgs.","messagePattern":"Field \"(.+?)\" is not a valid field of the entity \"(.+?)\" in PreUpdateEventArgs\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Event/PreUpdateEventArgs.php","lineNumber":93,"sourceCode":"    /**\n     * Sets the new value of this field.\n     */\n    public function setNewValue(string $field, mixed $value): void\n    {\n        $this->assertValidField($field);\n\n        $this->entityChangeSet[$field][1] = $value;\n    }\n\n    /**\n     * Asserts the field exists in changeset.\n     *\n     * @throws InvalidArgumentException\n     */\n    private function assertValidField(string $field): void\n    {\n        if (! isset($this->entityChangeSet[$field])) {\n            throw new InvalidArgumentException(sprintf(\n                'Field \"%s\" is not a valid field of the entity \"%s\" in PreUpdateEventArgs.',\n                $field,\n                get_debug_type($this->getObject()),\n            ));\n        }\n    }\n}\n","sourceCodeStart":75,"sourceCodeEnd":101,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Event/PreUpdateEventArgs.php#L75-L101","documentation":"InvalidArgumentException from PreUpdateEventArgs::assertValidField() (src/Event/PreUpdateEventArgs.php:93). getOldValue()/getNewValue()/setNewValue() only work with fields present in the entity's change set — the UnitOfWork computes changes before the PreUpdate event, and the args object wraps that computed change set. Asking for a field that was not changed (or does not exist) fails this assertion.","triggerScenarios":"Inside a preUpdate listener calling $args->setNewValue('status', ...) or $args->getOldValue('status') when 'status' is not in the change set: the new value equals the old one (field unchanged), the field name is misspelled/case-wrong, or you read fields of a related entity instead of the updated one. Also calling setNewValue for a field never set on the entity.","commonSituations":"Listeners that unconditionally do $args->setNewValue(\"updatedAt\", new DateTime()) even when only unrelated columns changed; renaming entity fields without updating listeners; assuming getOldValue works for any field rather than only changed ones; comparing values with != so a no-op change reaches the listener.","solutions":["Guard every access with $args->hasChangedField($field) before calling getOldValue/getNewValue/setNewValue.","If you must touch a field that is not part of the change set, mutate the entity and register it manually: $entity->setUpdatedAt(...); plus $args->setNewValue only for changed fields — or recompute via $em->getUnitOfWork()->computeChangeSet($args->getObject()).","Double-check field spelling and case against the mapping (the exception prints the actual entity class).","Avoid setting a value identical to the current one; the UnitOfWork will not mark it changed, so your guard matters."],"exampleFix":"// before\npublic function preUpdate(PreUpdateEventArgs $args): void {\n    $args->setNewValue('updatedAt', new DateTimeImmutable());\n        // throws if 'updatedAt' itself did not change\n}\n\n// after\npublic function preUpdate(PreUpdateEventArgs $args): void {\n    $entity = $args->getObject();\n    $entity->setUpdatedAt(new DateTimeImmutable());\n    // only inspect change-set fields through $args:\n    if ($args->hasChangedField('status')) {\n        $old = $args->getOldValue('status');\n        // ...\n    }\n    $em = $args->getObjectManager();\n    $em->getUnitOfWork()->recomputeSingleEntityChangeSet(\n        $em->getClassMetadata($entity::class), $entity\n    );\n}","handlingStrategy":"validation","validationCode":"if ($args->hasChangedField('status')) {\n    $old = $args->getOldValue('status');\n    $args->setNewValue('status', $newValue);\n}","typeGuard":null,"tryCatchPattern":"try {\n    $old = $args->getOldValue($field);\n} catch (\\InvalidArgumentException $e) {\n    // field not in this flush's change set — treat as 'no previous value'\n    $old = null;\n}","preventionTips":["Always gate getOldValue/getNewValue/setNewValue with hasChangedField().","Set audit columns on the entity itself and recompute the change set, instead of setNewValue on unchanged fields.","Keep listener field names in sync with mappings; add tests that flush unrelated-field changes."],"tags":["doctrine-orm","events","listeners","changeset"],"backgroundTag":"invalid-changeset-field","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}