Repository navigation
fix: Defined schema migration detects unchanged fields with an array, object or Date default value or Relation options as changed - #10926
Conversation
… object or Date default value or Relation options as changed
The schema migration compared the options of an existing field with `===`
on every key, so a field with an array or object default value (`[]`, `{}`,
Pointer, GeoPoint, File, Polygon), a Date default value declared as a
string, or a Relation with options was detected as changed at every start
and submitted again with the class update.
Compare the stored field with the field as it would be submitted, after
the same normalization done by `handleFields`, by value. A field whose
options really differ is still updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
🚀 Thanks for opening this pull request! We appreciate your effort in improving the project. Please let us know once your pull request is ready for review. Tip
Note Please respond to review comments from AI agents just like you would to comments from a human reviewer. Let the reviewer resolve their own comments, unless they have reviewed and accepted your commit, or agreed with your explanation for why the feedback was incorrect. Caution Pull requests must be written using an AI agent with human supervision. Pull requests written entirely by a human will likely be rejected, because of lower code quality, higher review effort and the higher risk of introducing bugs. Please note that AI review comments on this pull request alone do not satisfy this requirement. Our CI and AI review are safeguards, not development tools. If many issues are flagged, rethink your development approach. Invest more effort in planning and design rather than using review cycles to fix low-quality code. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Pull Request
Issue
Closes #10923
On every start, the schema migration compares the options of each existing field with its definition using
paramsAreEquals, which compares every key with===. Some unchanged fields never compare equal, so they are detected as changed and submitted again with the class update on every start:[],{}, or a Pointer, GeoPoint, File or Polygon default value;{ __type: 'Date', iso };required. Parse Server doesn't accept options on a Relation field (validateSchemaData), so they are never stored.Approach
A new method,
fieldParamsAreEquals, replacesparamsAreEqualsfor the field options only. The type check above it and the index comparison still useparamsAreEquals.The method compares the field stored in the database with the field as the migration would submit it, not with the raw definition:
handleFieldson a scratchParse.Schema. This applies the same normalization as the real update:{ __type: 'Date', iso };requiredvalues are dropped.JSON.parse(JSON.stringify(...)). This turns aDateobject into its ISO string and drops keys whose value isundefined, such astargetClass: undefined.util.isDeepStrictEqual.This is the same question
SchemaController.enforceFieldExistsanswers withJSON.stringifyequality when the field is submitted, but without depending on key order.Behavior:
requiredoption really changed is still detected and updated, including a nested change in an object default value.required: falsestill differs fromrequirednot set, becauserequired: falseis stored. Changing one into the other updates the field, as before.updateSchemaToDBcalls doesn't change.updateSchemastill updates every defined class on every start, for the class-level permissions. With the currentSchemaController, the re-submitted fields didn't cause any extra database write either:enforceFieldExistsskipped them. So this PR fixes the migration's change detection and shrinks the update payload to the fields that really changed; it doesn't reduce database operations on its own. The effect on database operations shows together with perf: Remove database operations for unchanged classes in schema migration on server start #10925, below.For a definition with 10 classes, each with one
Arrayfield (defaultValue: []) and oneObjectfield (defaultValue: {}), on the second start (MongoDB). Counted with Jasmine spies onDefinedSchemas.prototype.updateSchemaToDBand on theMongoSchemaCollectionmethods during the secondexecute():alphaupdateSchemaToDBcalls for these classes_SCHEMAreads / updates for the whole migration, system classes includedupdateFieldOptions)Together with #10925. #10925 skips the update of a class that has no field, index or class-level permission change. Without this PR, a class with any of the fields above always has fields to submit, so it is still updated on every start. With both changes, such a class is skipped too. Second start with an unchanged schema of 200 classes, each also with an
Arrayfield (defaultValue: []) and anObjectfield (defaultValue: {}), on MongoDB, counted as in #10924:updateClasscalls_SCHEMAreads_SCHEMAwritesalphaThe same holds at 10 and 50 classes and with
deleteExtraFields+recreateModifiedFields(603 → 603 → 200 → 0 updates at 200 classes). The two PRs touch different functions and apply cleanly in either order.Measured on a real application. I also measured the equivalent change on a real application, not on
alpha: the same application as in #10925, based on Parse Server 9.11, with about 280 classes, all defined through theschemaoption withstrict,deleteExtraFields,recreateModifiedFieldsandlockSchemasenabled, and Cloud Code. The change was ported to the compiled code. Here the base already includes the change of #10925, and the candidate adds this PR on top of it; both carry the same other local changes. Each build was started 4 times, 2 in each of two small ARM containers; each container ran the base, a second copy of the base as a control and the candidate, one at a time. Startup is measured from process start to the first successful/healthresponse, including the GraphQL schema. Medians, with min–max for the time:/healthThe operation counts were the same in all 4 starts of the base and of the candidate. Absolute values change from run to run, as the containers can land on different CPU models: the startup CPU of #10925 is 9.6 s here and 6.8 s in the run reported there, so only the comparison within the same run is meaningful. Startup CPU went down by 28% (control +1.1%). The time went down by 20%, but the control differed from the base by +7% in time in this run, so the time is less precise than the CPU and the counts. The 138 updates that remain match the 138 classes of that schema that declare indexes: they are the index sync that
performInitializationruns on every start (updateSchemaWithIndexes), which neither PR changes. This PR only affects the migration at startup: under steady load the CPU per request differed by +3.2%, right at the noise threshold of ±3.2%, and I don't read that as an effect of this change.Not in scope: a Date default value declared in Parse's own format,
{ __type: 'Date', iso: '...' }. The JS SDK'sParse.Schema.addFieldwraps it innew Date(...), which produces an invalid date, so1970-01-01T00:00:00.000Zis stored. That is a separate issue, and such a field is still detected as changed.This touches the same file as #10875, which adds
indexesAreEqualsand the sameisDeepStrictEqualimport. The index comparison is left untouched here, so any conflict should be limited to the import line and to the two new methods being next to each other.Tasks
Tests added in
spec/DefinedSchemas.spec.js:should not submit unchanged fields with object or array default values: array, nested object (withrequired), Date string, Pointer, GeoPoint, File and Polygon default values, and a String withrequired: false. On the second run, no field is submitted for the class and the stored schema is unchanged.should not submit unchanged relation fields with options: Relations withrequired: trueandrequired: false. Nothing is submitted, and the stored fields stay{ type: 'Relation', targetClass: '_User' }.should update fields with changed object or array default values and options:[]to[1], a nested object value, a Date default value,required: truetofalse, andrequired: falseto not set;The new tests ran locally on MongoDB only; Postgres is covered by CI. The first two tests and the last one fail on
alpha(9, 2 and 1 unexpected fields submitted).🤖 Generated with Claude Code