Skip to content

feature(psl): Support ignore directives on values in enums#5648

Open
Aijeyomah wants to merge 11 commits intoprisma:mainfrom
Aijeyomah:feature/support-enum-ignore-directive
Open

feature(psl): Support ignore directives on values in enums#5648
Aijeyomah wants to merge 11 commits intoprisma:mainfrom
Aijeyomah:feature/support-enum-ignore-directive

Conversation

@Aijeyomah
Copy link
Copy Markdown
Contributor

@Aijeyomah Aijeyomah commented Oct 13, 2025

Description

  • Support @ignore directives on values in enums types
  • Update psl/psl/Cargo.toml to enable all psl-core features for the test environment to resolve the unresolved import errors during cargo test -p psl
  • Add test to verify functionality

Note to reviewer

The issue raised included adding support for the @deprecated directive, but that work is out of scope for this pull request. I plan to open a separate PR to handle the @deprecated directive.

Closes #27911

Summary by CodeRabbit

  • New Features
    • Added support for the @ignore attribute on enum values so specific variants can be marked ignored and will be excluded from generated artifacts and schema outputs.
  • Rendering
    • Enum variant rendering now preserves and prints the @ignore annotation when present.
  • Tests
    • Added tests and assertion helpers to validate ignored enum-value behavior.

@Aijeyomah
Copy link
Copy Markdown
Contributor Author

@jacek-prisma @jkomyno, can you help review this PR? Thanks!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Oct 14, 2025

CodSpeed Performance Report

Merging #5648 will not alter performance

Comparing Aijeyomah:feature/support-enum-ignore-directive (bdaae63) with main (1d6ed60)

Summary

✅ 11 untouched

@Aijeyomah
Copy link
Copy Markdown
Contributor Author

@aqrln can you help review this PR? Also, I got the authorization error when I tried pushing the integration branch after following the steps(Community PRs: create a local branch for a branch coming from a fork)
to create a local integration branch to test my changes on Prisma repo.

@aqrln aqrln mentioned this pull request Oct 27, 2025
@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 27, 2025

@Aijeyomah

Also, I got the authorization error when I tried pushing the integration branch after following the steps(Community PRs: create a local branch for a branch coming from a fork)

I think this specific section is meant for the maintainers — sorry for the confusion.

I have approved the CI workflow, and I pushed an integration branch: #5659. If the build succeeds, an automated integration PR will be automatically opened on prisma/prisma side in about an hour or so.

Please let me know if/when the integration branch needs to be updated.

I won't have time to review the PR today, I'll have a look tomorrow.

Thank you for contributing so actively!

@aqrln aqrln added this to the 6.19.0 milestone Oct 27, 2025
@Aijeyomah
Copy link
Copy Markdown
Contributor Author

Aijeyomah commented Oct 28, 2025

@aqrln Thanks for creating the integration branch earlier 5659. After this branch was created and some of the checks were run (not all passed). I couldn't find any helpful resource on how to test the engines on prisma/prisma.

Yesterday, I tried testing the changes by switching to the automated integration branch on locally on Primsa mono-repo and running pnpm install, and also rebuilt the packages and tested, but I couldn't see my changes there, but I can see it works in the prisma-engine code. I think I am missing some crucial steps in testing these changes, and I'd appreciate if you could give me a guide on how to go about it.

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

@Aijeyomah hmm, it looks like something is wrong with the automation. I triggered an integration release manually now: https://github.com/prisma/prisma-engines/actions/runs/18876278132

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

Some tests are failing there because your branch is not up-to-date with main. I updated the integration branch (not the original branch in your fork though) and started another build: https://github.com/prisma/prisma-engines/actions/runs/18877914326

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

@Aijeyomah
Copy link
Copy Markdown
Contributor Author

p-to-date with main. I updated the integration branch (not the original branch in your fork though) and started another build: https://github.com/prisma/prisma-engines/actions/runs/18877914326

@aqrln I was almost excited until just one test failed. 28405 which cancelled the release to dev/integration npm. I really appreciate your help so far, but can you help look into the test here. Thanks!

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

@Aijeyomah that's a flaky test, ignore it. It's not related to your changes.

I see there are also some network-related issues on CI in this PR, I can restart the failed jobs after the in progress ones finish.

@aqrln
Copy link
Copy Markdown
Member

aqrln commented Oct 28, 2025

@Aijeyomah I also just restarted the cancelled release job, not sure why exactly it was cancelled. We have a huge number of CI jobs in progress right now because of the Prisma 7 work, and it looks like GitHub might be killing some of them because we might be running into some limits.

@Aijeyomah
Copy link
Copy Markdown
Contributor Author

@aqrln I've tested my changes and it works as expected. Thanks for helping out

@Aijeyomah
Copy link
Copy Markdown
Contributor Author

@aqrln @jacek-prisma I have tested this well on the Prisma monorepo, and it works as expected. Please, can you review? thanks

Aijeyomah and others added 6 commits January 26, 2026 13:40
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
…a#5683)

Remove the `url` property from `datasource` blocks in PSL, refactor the
code to handle URLs separately and update the tests.

Ref:
https://linear.app/prisma-company/issue/TML-1545/remove-url-datasource-attribute-from-psl

/prisma-branch next
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
@Aijeyomah Aijeyomah force-pushed the feature/support-enum-ignore-directive branch from 364b22c to 9b338a2 Compare January 26, 2026 12:47
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
Signed-off-by: Eti Ijeoma <ijayeti@gmail.com>
@Aijeyomah
Copy link
Copy Markdown
Contributor Author

@aqrln @jacek-prisma Reminder: I have tested this well on the Prisma monorepo, and it works as expected. Please, can you review? thanks

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 27, 2026

Walkthrough

The changes add support for the @ignore attribute on enum values across the parser database, query compiler, DMMF generation, tests, and schema renderer. Parsing, storage, querying, DMMF filtering, PSL rendering, and tests were updated to recognize and handle ignored enum variants.

Changes

Cohort / File(s) Summary
Parser database
psl/parser-database/src/attributes.rs, psl/parser-database/src/types.rs, psl/parser-database/src/walkers/enum.rs
Add ignored_values: HashSet<EnumValueId> to EnumAttributes, parse @ignore on enum values in resolve_enum_attributes, and add EnumValueWalker::is_ignored().
Tests & dev deps
psl/psl/tests/attributes/ignore_positive.rs, psl/psl/tests/common/asserts.rs, psl/psl/Cargo.toml
Add positive test for @ignore on enum values; extend test assertions with enum and enum-value helpers (assert_has_enum, assert_has_value, assert_ignored); add psl-core dev-dependency with backend features.
DMMF / Query compiler
query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs, query-compiler/core/src/query_document/parser.rs
Skip ignored enum values when building DMMF; refactor argument matching to preserve argument names with values and use name-aware required-argument validation.
Schema renderer
schema-engine/datamodel-renderer/src/datamodel/enumerator.rs
Add optional ignore field to EnumVariant, provide ignore() setter, initialize it, and render @ignore alongside other variant attributes.

Possibly related issues

  • prisma/prisma issue 27911 — Directly related: implements end-to-end @ignore support for enum values (storage, walker query, DMMF filtering, tests, and renderer).
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature being added: support for @ignore directives on enum values, which aligns with all the changes across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
schema-engine/datamodel-renderer/src/datamodel/enumerator.rs (1)

232-282: 🧹 Nitpick | 🔵 Trivial

Consider adding a test case for @ignore rendering.

The existing kitchen_sink test covers @map but doesn't exercise the new @ignore functionality on enum variants.

🧪 Suggested test addition
         let mut variant = EnumVariant::new("Invalid".into());
         variant.comment_out();
         r#enum.push_variant(variant);
         r#enum.push_variant("Black");
+
+        let mut ignored_variant = EnumVariant::new("Ignored".into());
+        ignored_variant.ignore();
+        r#enum.push_variant(ignored_variant);

         r#enum.schema("city_planning");

And update the expected output accordingly.

query-compiler/core/src/query_document/parser.rs (1)

209-233: ⚠️ Potential issue | 🟠 Major

Default argument values are no longer applied for omitted optional field arguments.

Line 210 says defaults should be processed, but Line 227 now returns None for all missing non-required arguments. That drops schema defaults and can change query behavior.

💡 Suggested fix
-                    None if !input_field.is_required() => None,
+                    None if !input_field.is_required() => input_field
+                        .default_value
+                        .as_ref()
+                        .and_then(|default_value| default_value.get())
+                        .map(|default_value| {
+                            self.parse_input_value(
+                                selection_path.clone(),
+                                argument_path,
+                                default_value.into(),
+                                input_field.field_types(),
+                                query_schema,
+                                input_field.is_parameterizable(),
+                            )
+                            .map(|value| ParsedArgument {
+                                name: input_field.name.clone().into_owned(),
+                                value,
+                            })
+                        }),

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94a226b and 22bae69.

📒 Files selected for processing (9)
  • psl/parser-database/src/attributes.rs
  • psl/parser-database/src/types.rs
  • psl/parser-database/src/walkers/enum.rs
  • psl/psl/Cargo.toml
  • psl/psl/tests/attributes/ignore_positive.rs
  • psl/psl/tests/common/asserts.rs
  • query-compiler/core/src/query_document/parser.rs
  • query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs
  • schema-engine/datamodel-renderer/src/datamodel/enumerator.rs

Comment on lines +741 to +742
/// @ignore on enum values.
pub(super) ignored_values: std::collections::HashSet<EnumValueId>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider using FxHashSet for consistency and performance.

The file uses rustc_hash::FxHashMap (aliased as HashMap) for other collections like mapped_values, but ignored_values uses std::collections::HashSet. For small integer keys like EnumValueId, FxHashSet provides better performance and maintains consistency with the rest of the codebase.

♻️ Suggested change
+use rustc_hash::FxHashSet;
 // ... in EnumAttributes struct:
     /// `@ignore` on enum values.
-    pub(super) ignored_values: std::collections::HashSet<EnumValueId>,
+    pub(super) ignored_values: FxHashSet<EnumValueId>,

Note: You'll need to add FxHashSet to the imports at the top of the file alongside FxHashMap.

Comment on lines +143 to +150

#[track_caller]
fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> {
self.db
.walk_enums()
.find(|e| e.name() == name)
.expect("Enum {name} not found")
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the expect() message formatting.

The error message uses {name} as a literal string rather than interpolating the variable. This should use a format string.

🐛 Proposed fix
     #[track_caller]
     fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> {
         self.db
             .walk_enums()
             .find(|e| e.name() == name)
-            .expect("Enum {name} not found")
+            .unwrap_or_else(|| panic!("Enum {name} not found"))
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[track_caller]
fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> {
self.db
.walk_enums()
.find(|e| e.name() == name)
.expect("Enum {name} not found")
}
#[track_caller]
fn assert_has_enum(&'a self, name: &str) -> walkers::EnumWalker<'a> {
self.db
.walk_enums()
.find(|e| e.name() == name)
.unwrap_or_else(|| panic!("Enum {} not found", name))
}

Comment on lines +804 to +815
pub(crate) trait EnumAssert<'a> {
fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a>;
}

impl<'a> EnumAssert<'a> for walkers::EnumWalker<'a> {
#[track_caller]
fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a> {
self.values()
.find(|v| v.name() == name)
.expect("Enum value {name} not found")
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the expect() message formatting.

Same issue as assert_has_enum - the error message doesn't interpolate {name}.

🐛 Proposed fix
     #[track_caller]
     fn assert_has_value(&'a self, name: &str) -> walkers::EnumValueWalker<'a> {
         self.values()
             .find(|v| v.name() == name)
-            .expect("Enum value {name} not found")
+            .unwrap_or_else(|| panic!("Enum value {name} not found"))
     }

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs`:
- Around line 50-55: Refactor the enum value loop in enum_to_dmmf to use
iterator adapters: replace the for/if/continue pattern over en.values() with
en.values().filter(|v| !v.is_ignored()).map(enum_value_to_dmmf).collect() so
Enum.values is built declaratively; update the Enum construction in enum_to_dmmf
to assign values via that filtered map and ensure db_name and documentation are
preserved as before.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5fdbb47c-24fa-489a-8f82-aaeedbe7f360

📥 Commits

Reviewing files that changed from the base of the PR and between 22bae69 and f912874.

📒 Files selected for processing (1)
  • query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs

Comment on lines 50 to 55
for enum_value in en.values() {
if enum_value.is_ignored() {
continue;
}
enm.values.push(enum_value_to_dmmf(enum_value));
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check for test coverage of ignored enum values in DMMF rendering

# Look for `@ignore` on enum values in test files
echo "=== Checking DMMF test files for `@ignore` on enum values ==="
fd -e prisma . query-compiler/dmmf/test_files --exec grep -l '@ignore' {} \; 2>/dev/null || echo "No `@ignore` found in DMMF test files"

# Show any matches in detail
echo ""
echo "=== Detailed matches ==="
rg -n '@ignore' query-compiler/dmmf/test_files/ 2>/dev/null || echo "No matches"

# Also check for enum-related ignore tests in PSL tests
echo ""
echo "=== PSL ignore tests for enum values ==="
rg -n -A5 'ignore.*enum|enum.*ignore' psl/psl/tests/attributes/ --type rust 2>/dev/null | head -50

Repository: prisma/prisma-engines

Length of output: 1202


Consider using .filter() for consistency with existing patterns.

The change correctly excludes ignored enum values from DMMF output. However, other filtering operations in this file use the .filter() iterator method (e.g., lines 28-29, 75, 141), whereas this uses an if/continue pattern.

♻️ Suggested refactor using `.filter()`
-    for enum_value in en.values() {
-        if enum_value.is_ignored() {
-            continue;
-        }
+    for enum_value in en.values().filter(|v| !v.is_ignored()) {
         enm.values.push(enum_value_to_dmmf(enum_value));
     }

Alternatively, restructure the entire function to match the more declarative style used elsewhere:

fn enum_to_dmmf(en: walkers::EnumWalker<'_>) -> Enum {
    Enum {
        name: en.name().to_owned(),
        values: en
            .values()
            .filter(|v| !v.is_ignored())
            .map(enum_value_to_dmmf)
            .collect(),
        db_name: en.mapped_name().map(ToOwned::to_owned),
        documentation: en.ast_enum().documentation().map(ToOwned::to_owned),
    }
}

Test coverage exists in PSL tests (psl/psl/tests/attributes/ignore_positive.rs::allow_ignore_on_enum_values) validating that enum values with @ignore are handled correctly.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
for enum_value in en.values() {
if enum_value.is_ignored() {
continue;
}
enm.values.push(enum_value_to_dmmf(enum_value));
}
for enum_value in en.values().filter(|v| !v.is_ignored()) {
enm.values.push(enum_value_to_dmmf(enum_value));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@query-compiler/dmmf/src/ast_builders/datamodel_ast_builder.rs` around lines
50 - 55, Refactor the enum value loop in enum_to_dmmf to use iterator adapters:
replace the for/if/continue pattern over en.values() with en.values().filter(|v|
!v.is_ignored()).map(enum_value_to_dmmf).collect() so Enum.values is built
declaratively; update the Enum construction in enum_to_dmmf to assign values via
that filtered map and ensure db_name and documentation are preserved as before.

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.

Support @ignore directives on enum types

3 participants