Skip to content

fix: Defined schema migration detects unchanged fields with an array, object or Date default value or Relation options as changed - #10926

Open
andreafalzetti wants to merge 1 commit into
parse-community:alphafrom
andreafalzetti:fix/defined-schemas-field-options
Open

andreafalzetti wants to merge 1 commit into
parse-community:alphafrom
andreafalzetti:fix/defined-schemas-field-options

Conversation

@andreafalzetti

@andreafalzetti andreafalzetti commented Dec 4, 2026 •

Copy link
Copy Markdown

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:

  • fields with an array or object default value: [], {}, or a Pointer, GeoPoint, File or Polygon default value;
  • Date fields with a default value declared as a string. The database holds { __type: 'Date', iso };
  • Relation fields with an option such as required. Parse Server doesn't accept options on a Relation field (validateSchemaData), so they are never stored.

Approach

A new method, fieldParamsAreEquals, replaces paramsAreEquals for the field options only. The type check above it and the index comparison still use paramsAreEquals.

The method compares the field stored in the database with the field as the migration would submit it, not with the raw definition:

  1. It runs the definition through handleFields on a scratch Parse.Schema. This applies the same normalization as the real update:
    • a Date default value is converted to { __type: 'Date', iso };
    • the options of a Relation are dropped, since Parse Server rejects them;
    • non-boolean required values are dropped.
  2. Both sides go through JSON.parse(JSON.stringify(...)). This turns a Date object into its ISO string and drops keys whose value is undefined, such as targetClass: undefined.
  3. The two sides are compared with util.isDeepStrictEqual.

This is the same question SchemaController.enforceFieldExists answers with JSON.stringify equality when the field is submitted, but without depending on key order.

Behavior:

  • Unchanged fields with array, object, Pointer, GeoPoint, File, Polygon or Date-string default values, and unchanged Relation fields with declared options, are no longer submitted again on every start.
  • A field whose default value or required option really changed is still detected and updated, including a nested change in an object default value.
  • required: false still differs from required not set, because required: false is stored. Changing one into the other updates the field, as before.
  • The number of updateSchemaToDB calls doesn't change. updateSchema still updates every defined class on every start, for the class-level permissions. With the current SchemaController, the re-submitted fields didn't cause any extra database write either: enforceFieldExists skipped 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 Array field (defaultValue: []) and one Object field (defaultValue: {}), on the second start (MongoDB). Counted with Jasmine spies on DefinedSchemas.prototype.updateSchemaToDB and on the MongoSchemaCollection methods during the second execute():

alpha this PR
classes whose update carries fields 10 0
fields submitted again 20 0
updateSchemaToDB calls for these classes 10 10
_SCHEMA reads / updates for the whole migration, system classes included 29 / 26 29 / 26
field option writes (updateFieldOptions) 0 0

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 Array field (defaultValue: []) and an Object field (defaultValue: {}), on MongoDB, counted as in #10924:

Build updateClass calls _SCHEMA reads _SCHEMA writes
alpha 203 409 406
this PR 203 409 406
#10925 200 402 400
#10925 and this PR 0 1 0

The 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 the schema option with strict, deleteExtraFields, recreateModifiedFields and lockSchemas enabled, 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 /health response, including the GraphQL schema. Medians, with min–max for the time:

base (#10925) control (same build as base) #10925 and this PR
time to first /health 10.2 s (9.6–10.4) 10.9 s (10.5–11.0) 8.1 s (7.9–8.6)
process CPU during startup 9.6 s 9.7 s 6.9 s
MongoDB operations 828 828 430
of which queries + getMore 139 + 135 139 + 135 6 + 2
of which updates 270 270 138
data returned by MongoDB 42 MB 42 MB 0.7 MB

The 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 performInitialization runs 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's Parse.Schema.addField wraps it in new Date(...), which produces an invalid date, so 1970-01-01T00:00:00.000Z is stored. That is a separate issue, and such a field is still detected as changed.

This touches the same file as #10875, which adds indexesAreEquals and the same isDeepStrictEqual import. 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

  • Add tests
  • Add changes to documentation (guides, repository pages, code comments)

Tests added in spec/DefinedSchemas.spec.js:

  • should not submit unchanged fields with object or array default values: array, nested object (with required), Date string, Pointer, GeoPoint, File and Polygon default values, and a String with required: 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 with required: true and required: 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:
    • changes [] to [1], a nested object value, a Date default value, required: true to false, and required: false to not set;
    • only those five fields are submitted, and the stored schema reflects each change;
    • an unchanged array default in the same class is not submitted.

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

… 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>
@parse-github-assistant

Copy link
Copy Markdown

🚀 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

  • Keep pull requests small. Large PRs will be rejected. Break complex features into smaller, incremental PRs.
  • Use Test Driven Development. Write failing tests before implementing functionality. Ensure tests pass.
  • Group code into logical blocks. Add a short comment before each block to explain its purpose.
  • We offer conceptual guidance. Coding is up to you. PRs must be merge-ready for human review.
  • Our review focuses on concept, not quality. PRs with code issues will be rejected. Use an AI agent.
  • Human review time is precious. Avoid review ping-pong. Inspect and test your AI-generated code.

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.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Defined schema migrations now compare cloud field parameters with normalized configured fields. Tests cover unchanged defaults and options, as well as updates when those values change.

Changes: Defined schema field comparison

Layer / File(s) Summary
Normalized comparison and regression tests
src/SchemaMigrations/DefinedSchemas.js, spec/DefinedSchemas.spec.js
updateSchema compares cloud fields with fields normalized by handleFields. Tests check that unchanged fields are omitted and changed defaults or options are submitted.

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Low

Possibly related issues

  • parse-community/parse-server#10924 reports repeated class updates for unchanged schemas. This change addresses field-option comparison, but does not address the separate class-level permission comparison.

Possibly related PRs

Suggested reviewers: sadortun, mtrezza

Merge Risk: Minimal · up to 9c3ff

This change stops unchanged schema fields from being flagged as changed on every start, while real changes are still detected. No merge-blocking risk was found.

Pre-merge checks: Passed 6

Check name Status Explanation
Title check Passed The title begins with the required prefix "fix:" and the first letter after it is capitalized ("Defined"). It describes the main change: unchanged fields with array, object, or Date defaults, and Rela…
Linked Issues check Passed Issue #10923 requires that unchanged fields are not detected as changed, and that real changes to defaultValue or required are still detected. The diff in src/SchemaMigrations/DefinedSchemas.js replac…
Out of Scope Changes check Passed The source change is limited to src/SchemaMigrations/DefinedSchemas.js. It adds the isDeepStrictEqual import, the fieldParamsAreEquals method, and one call site that replaces paramsAreEquals for field…
Description check Passed The description follows the repository template. It has the Pull Request, Issue, Approach and Tasks sections. It links issue #10923 and explains the root cause: strict === comparison of field options,…
Security Check Passed Summary: The diff adds no security-relevant pattern. It changes two files: src/SchemaMigrations/DefinedSchemas.js and spec/DefinedSchemas.spec.js. Evidence from the diff: - The only source change …
Engage In Review Feedback Passed ## Result: PASS The check forbids ignoring or resolving review feedback without first engaging in discussion. The supplied review_comments context states: "No CodeRabbit review threads were returned…
Full details: Title check

Explanation

The title begins with the required prefix "fix:" and the first letter after it is capitalized ("Defined"). It describes the main change: unchanged fields with array, object, or Date defaults, and Relation options, were wrongly detected as changed. The title is long (129 characters) but still specific and matches the changeset.

Full details: Linked Issues check

Explanation

Issue #10923 requires that unchanged fields are not detected as changed, and that real changes to defaultValue or required are still detected. The diff in src/SchemaMigrations/DefinedSchemas.js replaces paramsAreEquals with fieldParamsAreEquals for the field options comparison. The new method normalizes the local definition through the existing handleFields on a scratch Parse.Schema. It then compares the stored field and the submitted field after a JSON round trip, using util.isDeepStrictEqual. This covers the three cases in the issue: array, object and Pointer/GeoPoint/File/Polygon defaults (value comparison instead of identity), Date string defaults (converted by handleFields), and Relation options (dropped by handleFields). Nested changes still differ under deep equality, so they are detected. The spec additions in spec/DefinedSchemas.spec.js cover unchanged fields, Relation options, and changed defaults and required options. I did not run the tests. I read only the source diff, and I did not re-read the handleFields body in full, so the Date normalization claim rests on the PR description and tests. The issue's coding requirements appear to be met.

Full details: Out of Scope Changes check

Explanation

The source change is limited to src/SchemaMigrations/DefinedSchemas.js. It adds the isDeepStrictEqual import, the fieldParamsAreEquals method, and one call site that replaces paramsAreEquals for field options. The type check and index comparison are unchanged. The spec additions test the same change. The benchmark tables and the notes on #10924, #10925 and #10875 are measurement and coordination text, not code changes. The description states the Date { __type: 'Date', iso } case is out of scope, and the code does not attempt to address it. No unrelated code change is present in the reviewed diff.

Full details: Description check

Explanation

The description follows the repository template. It has the Pull Request, Issue, Approach and Tasks sections. It links issue #10923 and explains the root cause: strict === comparison of field options, which flags unchanged array, object, Pointer, GeoPoint, File, Polygon, Date-string and Relation-option fields as changed. The Approach section describes the new fieldParamsAreEquals method, its normalization steps, the expected behavior, and the measured effects with and without #10925. The Tasks section marks tests and documentation as done. The tests are listed by name and behavior. Minor gap: the Tasks list omits the security-check and Parse JS SDK items, and the template's other items are not addressed. These omissions are non-critical for this change.

Full details: Security Check

Explanation

Summary: The diff adds no security-relevant pattern. It changes two files: src/SchemaMigrations/DefinedSchemas.js and spec/DefinedSchemas.spec.js. Evidence from the diff: - The only source change is at the field-options comparison in updateSchema (line 279). paramsAreEquals is replaced by a new fieldParamsAreEquals. The result only decides whether a field goes into fieldsWithChangedParams. - fieldParamsAreEquals builds a scratch new Parse.Schema(className), runs handleFields on it, and compares JSON round-trip copies with util.isDeepStrictEqual. Parse.Schema is local object construction. It makes no database or network call. There is no eval, no dynamic code, no string-built query, and no new dependency. util is a Node built-in. - The input comes from developer-defined schema configuration and from the stored schema. No request input reaches this path. - Type and targetClass checks still use paramsAreEquals. Field deletion, field recreation, protected-field handling, and index handling are unchanged. Risk analysis: The only behavioral change is that unchanged fields are not re-submitted. Real changes to defaultValue or required still reach handleFields. The edge cases of JSON comparison (for example undefined keys or NaN) do not touch authentication, ACLs, or class-level permissions. They affect only which schema field options are re-applied at startup. No advisory-type issue (injection, auth bypass, data exposure, unsafe deserialization, or privilege change) is introduced. Conclusion: No problematic security pattern appears in the changed code. The check passes.

Full details: Engage In Review Feedback

Explanation

Result: PASS The check forbids ignoring or resolving review feedback without first engaging in discussion. The supplied review_comments context states: "No CodeRabbit review threads were returned." No review feedback exists for this pull request. The check therefore has no feedback to ignore or resolve, and no failure condition applies. ## Evidence - Primary PR: parse-community/parse-server #10926, author andreafalzetti, base alpha, head fix/defined-schemas-field-options. - Review comments: none returned. The supplied record covers all returned review threads. - Scope: the check concerns review-feedback handling only. It does not assess the code change. I did not evaluate the code fix. ## Limitation The available evidence covers only the threads returned in this run. If the provider has review threads that were not returned, this verdict does not cover them. Re-run the check if new review feedback appears. I am confident in this PASS. The check cannot fail on feedback that does not exist.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Biome (2.6.8)

src/SchemaMigrations/DefinedSchemas.js

File contains syntax errors that prevent linting: Line 15: return types can only be used in TypeScript files; Line 16: return types can only be used in TypeScript files; Line 17: return types can only be used in TypeScript files; Line 18: return types can only be used in TypeScript files; Line 19: return types can only be used in TypeScript files; Line 20: return types can only be used in TypeScript files; Line 22: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 22: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 38: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 38: return type annotation are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 49: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove th

... [truncated 2734 characters] ...

cript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 451: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 452: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 453: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 461: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 461: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.; Line 461: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1e45bdcb-730a-487b-81e6-dd4373e11bd1
Commits

Reviewing files that changed from the base of the PR and between 3e5b31f and 9c3ff87.

Files selected for processing: 2

  • spec/DefinedSchemas.spec.js
  • src/SchemaMigrations/DefinedSchemas.js

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Defined schema migration detects unchanged fields with an array, object or Date default value or Relation options as changed

1 participant