Skip to content

Conversation

Moumouls
Copy link
Member

@Moumouls Moumouls commented Aug 23, 2022

New Pull Request Checklist

Issue Description

Related issue: #8136

Approach

Add an option on both adapters

TODOs before merging

  • Add tests
  • Add changes to documentation (guides, repository pages, in-code descriptions)
  • Add security check
  • Add new Parse Error codes to Parse JS SDK
  • A changelog entry is created automatically using the pull request title (do not manually add a changelog entry)

Summary by CodeRabbit

  • New Features

    • Added an optional setting to disable index-field validation for MongoDB and Postgres storage adapters, allowing creation of indexes for fields that don’t yet exist. Default behavior unchanged.
  • Tests

    • Added tests verifying index creation succeeds when validation is disabled.
    • Added a test confirming file upload and retrieval work when the new option is enabled.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Aug 23, 2022

🚀 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.

@Moumouls Moumouls requested a review from a team August 23, 2022 09:54
@codecov
Copy link

codecov bot commented Aug 23, 2022

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.00%. Comparing base (f024d53) to head (7bd3834).
⚠️ Report is 2 commits behind head on alpha.

Files with missing lines Patch % Lines
...dapters/Storage/Postgres/PostgresStorageAdapter.js 83.33% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #8137   +/-   ##
=======================================
  Coverage   92.99%   93.00%           
=======================================
  Files         187      187           
  Lines       15097    15105    +8     
  Branches      174      174           
=======================================
+ Hits        14040    14048    +8     
  Misses       1045     1045           
  Partials       12       12           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mtrezza mtrezza linked an issue Aug 25, 2022 that may be closed by this pull request
3 tasks
Copy link
Member

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint is failing

await self.createIndexes(className, insertedIndexes, t);
}
} catch (e) {
const columnDoesNotExistError = e.errors?.[0]?.code === '42703';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional chaining is available from Node 14; Parse Server still supports Node 12.

Copy link
Member

@mtrezza mtrezza Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use optional changing now, Parse Server 6 supports Node >=14; does lint on the latest alpha commit still report an error if you use optional chaining?

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: disable index validation feat: Disable index validation Nov 14, 2022
@Moumouls Moumouls requested review from a team and mtrezza November 14, 2022 23:06
@Moumouls Moumouls changed the title feat: Disable index validation feat: disable index validation Nov 14, 2022
@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title feat: disable index validation feat: Disable index validation Nov 14, 2022
@Moumouls
Copy link
Member Author

Lint fixed @mtrezza

…moumouls/disableIndexValidation

# Conflicts:
#	src/Adapters/Files/GridFSBucketAdapter.js
#	src/Adapters/Storage/Mongo/MongoStorageAdapter.js
#	src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Copy link

coderabbitai bot commented Sep 13, 2025

📝 Walkthrough

Walkthrough

Adds a runtime option disableIndexFieldValidation read and removed from adapter options; Mongo and Postgres storage adapters use it to optionally skip per-field index existence checks (Postgres also conditionally swallows 42703 column-missing errors). Tests added covering GridFS upload and schema index behavior.

Changes

Cohort / File(s) Summary
Tests: option coverage
spec/GridFSBucketStorageAdapter.spec.js, spec/schemas.spec.js
Add tests exercising disableIndexFieldValidation: GridFS upload with the option present; schema index creation on a non-existent field and defaulting the flag to false in test setup.
Mongo storage adapter
src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Add public boolean disableIndexFieldValidation initialized from mongoOptions; remove it from options passed to the driver; skip per-field index existence checks when enabled.
Postgres storage adapter
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Add public boolean disableIndexFieldValidation read from databaseOptions and stripped from client options; conditionally skip per-field existence validation; wrap index creation to detect Postgres 42703 and suppress it when the flag is true. Also fix some ST_DistanceSphere query placeholder formatting.
GridFS bucket adapter
src/Adapters/Files/GridFSBucketAdapter.js
Prevent forwarding disableIndexFieldValidation to the Mongo driver by deleting it from _mongoOptions before connecting.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant API
  participant Adapter as StorageAdapter (Mongo/Postgres)
  participant DB

  Client->>API: PUT /schemas/:class (indexes payload)
  API->>Adapter: setIndexesWithSchemaFormat(className, indexes)
  alt disableIndexFieldValidation = false
    Adapter->>Adapter: Validate each index field exists in schema
    Adapter-->>API: Return/throw validation error if unknown field
  else disableIndexFieldValidation = true
    note right of Adapter #DFF2E1: Skip schema-field existence checks
    Adapter->>DB: Create/ensure index(es)
    alt Postgres only
      DB-->>Adapter: Error 42703 (column missing)?
      alt flag=false
        Adapter-->>API: Propagate error
      else flag=true
        note right of Adapter #FFF3D6: Swallow 42703 and continue
      end
    end
    Adapter-->>API: Index creation result
  end
  API-->>Client: Response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • mtrezza

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description does not follow the required repository template: it uses incorrect heading levels, omits the top-level “## Pull Request” header with security and license links, lacks a proper “## Issue” section with “Closes: #8136,” and misnames the “Tasks” section, resulting in non-compliance with the specified structure. Please revise the description to match the provided template by adding the “## Pull Request” header with the security and license links, filling in “## Issue” with “Closes: #8136,” renaming sections to “## Approach” and “## Tasks,” and ensuring all required fields and headings are present as specified.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Title Check ✅ Passed The title clearly and concisely describes the primary change of adding a feature to disable index-field validation so that indexes can be created for non-existent fields, matching the PR’s main objective and conventional commit style without unnecessary detail.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Sep 13, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@Moumouls
Copy link
Member Author

@mtrezza pr refreshed :)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
spec/schemas.spec.js (1)

3011-3011: Use adapter from config to avoid implicit globals

Prefer referencing the adapter via config to prevent scope issues.

-      databaseAdapter.disableIndexFieldValidation = false;
+      config.database.adapter.disableIndexFieldValidation = false;
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (1)

1015-1024: Optional: document/verify behavior when index isn’t physically created

With the flag enabled, _SCHEMA will list indexes that PG didn’t create. Consider a follow-up to retry index creation when the referenced field is later added, or document this divergence.

spec/GridFSBucketStorageAdapter.spec.js (1)

424-431: Nit: test name says databaseOptions but adapter arg is mongoOptions

Minor clarity tweak.

-it('properly upload a file when disableIndexFieldValidation exist in databaseOptions', async () => {
+it('properly uploads a file when disableIndexFieldValidation is present in mongoOptions', async () => {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82fdb0d and 8e4e655.

📒 Files selected for processing (5)
  • spec/GridFSBucketStorageAdapter.spec.js (1 hunks)
  • spec/schemas.spec.js (2 hunks)
  • src/Adapters/Files/GridFSBucketAdapter.js (1 hunks)
  • src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3 hunks)
  • src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
spec/GridFSBucketStorageAdapter.spec.js (3)
spec/helper.js (2)
  • GridFSBucketAdapter (44-45)
  • databaseURI (57-57)
src/Adapters/Files/GridFSBucketAdapter.js (1)
  • GridFSBucketAdapter (15-253)
src/cryptoUtils.js (1)
  • randomString (22-33)
spec/schemas.spec.js (2)
spec/helper.js (1)
  • databaseAdapter (56-56)
src/Routers/SchemasRouter.js (2)
  • response (49-54)
  • response (62-68)
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (2)
src/Controllers/index.js (10)
  • options (58-67)
  • options (81-89)
  • options (102-102)
  • options (110-110)
  • options (130-130)
  • options (140-140)
  • options (141-141)
  • options (161-161)
  • options (173-173)
  • options (211-211)
src/Adapters/Storage/Postgres/PostgresConfigParser.js (1)
  • databaseOptions (3-3)
🪛 Biome (2.1.2)
src/Adapters/Storage/Mongo/MongoStorageAdapter.js

[error] 143-143: return types can only be used in TypeScript files

remove this type annotation

(parse)

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

[error] 865-865: return types can only be used in TypeScript files

remove this type annotation

(parse)


[error] 867-867: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Node 20
  • GitHub Check: Redis Cache
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: Node 18
  • GitHub Check: MongoDB 6, ReplicaSet
  • GitHub Check: MongoDB 7, ReplicaSet
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: Docker Build
🔇 Additional comments (9)
spec/schemas.spec.js (1)

3040-3061: LGTM: test covers disabled index-field validation path

Test correctly toggles the flag and asserts index persistence in the response.

src/Adapters/Storage/Mongo/MongoStorageAdapter.js (3)

143-143: LGTM: new adapter flag is well-scoped

Public flag declaration is consistent with existing Flow-style fields.


156-160: LGTM: option plumbed and stripped before passing to driver

You read from mongoOptions and remove it from _mongoOptions—good.


294-305: LGTM: gated index field validation

Skipping per-field checks when disableIndexFieldValidation is true is correctly implemented and still validates pointer key form.

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (3)

865-865: LGTM: new adapter flag

Property addition aligns with existing style.


871-876: LGTM: constructor wiring and option stripping

Flag is read from databaseOptions and removed before client creation.


997-1000: LGTM: gated index field validation

Conditional check mirrors Mongo adapter behavior.

spec/GridFSBucketStorageAdapter.spec.js (1)

424-431: LGTM: verifies option filtering doesn’t break uploads

Test ensures unknown option is ignored by the Mongo client wrapper.

src/Adapters/Files/GridFSBucketAdapter.js (1)

40-43: LGTM: filter out disableIndexFieldValidation before connecting

Consistent with storage adapters; avoids passing unknown driver options.

@Moumouls
Copy link
Member Author

@mtrezza we should be good to go here

@Moumouls
Copy link
Member Author

Moumouls commented Oct 8, 2025

fixed error shallowing @mtrezza

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 8, 2025
@Moumouls
Copy link
Member Author

Moumouls commented Oct 8, 2025

@mtrezza fixed the error code detection i hope everything pass now

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (1)

1012-1028: Consider using the defined constant and clarifying the error handling logic.

While the logic is functionally correct, it could be improved for maintainability:

  1. Use the PostgresMissingColumnError constant (defined at line 17) instead of the hard-coded '42703'
  2. The nested conditionals could be simplified for clarity

Apply this diff for better readability:

       try {
         if (insertedIndexes.length > 0) {
           await self.createIndexes(className, insertedIndexes, t);
         }
       } catch (e) {
-        // pg-promise use Batch error see https://github.com/vitaly-t/spex/blob/e572030f261be1a8e9341fc6f637e36ad07f5231/src/errors/batch.js#L59
-        const columnDoesNotExistError = e.getErrors && e.getErrors()[0] && e.getErrors()[0].code === '42703';
-        // Specific case when the column does not exist
-        if (columnDoesNotExistError) {
-          // If the disableIndexFieldValidation is true, we should ignore the error
-          if (!this.disableIndexFieldValidation) {
-            throw e;
-          }
-        } else {
-          throw e;
-        }
+        // pg-promise uses Batch error - see https://github.com/vitaly-t/spex/blob/e572030f261be1a8e9341fc6f637e36ad07f5231/src/errors/batch.js#L59
+        const errorCode = e.getErrors && e.getErrors()[0] && e.getErrors()[0].code;
+        const isColumnMissingError = errorCode === PostgresMissingColumnError;
+        const shouldSwallow = this.disableIndexFieldValidation && isColumnMissingError;
+        
+        if (!shouldSwallow) {
+          throw e;
+        }
+        // If disableIndexFieldValidation is true and column is missing, swallow the error
       }

This approach:

  • Uses the defined constant for consistency
  • Makes the "swallow only when both conditions are met" logic explicit
  • Reduces nesting and improves readability
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3647128 and 55071e6.

📒 Files selected for processing (1)
  • src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (8 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (3)
src/Controllers/index.js (10)
  • options (58-67)
  • options (81-89)
  • options (102-102)
  • options (110-110)
  • options (130-130)
  • options (140-140)
  • options (141-141)
  • options (161-161)
  • options (173-173)
  • options (211-211)
src/Adapters/Storage/Postgres/PostgresConfigParser.js (1)
  • databaseOptions (3-3)
src/Adapters/Storage/Postgres/PostgresClient.js (2)
  • createClient (3-36)
  • client (19-19)
🪛 Biome (2.1.2)
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

[error] 862-862: return types can only be used in TypeScript files

remove this type annotation

(parse)


[error] 864-864: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: PostgreSQL 17, PostGIS 3.5
  • GitHub Check: PostgreSQL 18, PostGIS 3.6
  • GitHub Check: PostgreSQL 15, PostGIS 3.4
  • GitHub Check: Node 20
  • GitHub Check: PostgreSQL 16, PostGIS 3.5
  • GitHub Check: PostgreSQL 15, PostGIS 3.3
  • GitHub Check: Redis Cache
  • GitHub Check: MongoDB 6, ReplicaSet
  • GitHub Check: Node 18
  • GitHub Check: MongoDB 8, ReplicaSet
  • GitHub Check: PostgreSQL 15, PostGIS 3.5
  • GitHub Check: MongoDB 7, ReplicaSet
🔇 Additional comments (9)
src/Adapters/Storage/Postgres/PostgresStorageAdapter.js (9)

864-873: LGTM!

The initialization and cleanup of disableIndexFieldValidation follows the same pattern as other adapter-specific options.


630-631: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


634-635: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


682-683: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


1645-1646: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


1652-1653: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


1763-1764: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


2202-2203: LGTM!

The template string fix correctly interpolates the index expressions for SQL placeholders.


994-1002: LGTM!

The conditional field validation correctly skips the check when disableIndexFieldValidation is enabled, allowing indexes on fields that may not exist yet.

@Moumouls
Copy link
Member Author

Moumouls commented Oct 8, 2025

test on green @mtrezza !

@mtrezza mtrezza changed the title feat: Disable index validation feat: Disable index-field validation to create of indexes for fields that don’t yet exist Oct 9, 2025
@mtrezza mtrezza changed the title feat: Disable index-field validation to create of indexes for fields that don’t yet exist feat: Disable index-field validation to create index for fields that don’t yet exist Oct 9, 2025
@mtrezza mtrezza changed the title feat: Disable index-field validation to create index for fields that don’t yet exist feat: Disable index-field validation to create index for fields that don't yet exist Oct 9, 2025
@mtrezza mtrezza merged commit 1b23475 into parse-community:alpha Oct 9, 2025
24 of 26 checks passed
parseplatformorg pushed a commit that referenced this pull request Oct 9, 2025
# [8.3.0-alpha.4](8.3.0-alpha.3...8.3.0-alpha.4) (2025-10-09)

### Features

* Disable index-field validation to create index for fields that don't yet exist ([#8137](#8137)) ([1b23475](1b23475))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 8.3.0-alpha.4

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Oct 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released-alpha Released as alpha version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow to disable index validation on database adapters
3 participants