Skip to content

Feature - Warn on Unknown Flags#12842

Open
sriramr98 wants to merge 5 commits into
mainfrom
feat/strict-flags
Open

Feature - Warn on Unknown Flags#12842
sriramr98 wants to merge 5 commits into
mainfrom
feat/strict-flags

Conversation

@sriramr98
Copy link
Copy Markdown
Contributor

@sriramr98 sriramr98 commented Apr 15, 2026

Resolves #12590

Problem

When users set flags in dbt_project.yml that dbt doesn't recognize (e.g., typos like prrint instead of print), dbt silently ignores them. There's no feedback to the user that their configuration is being ignored, leading to confusion when expected behavior doesn't change.

Solution

Added validation in read_project_flags() at core/dbt/config/project.py that compares the user's flags against known ProjectFlags field names. Unknown flags trigger a warning via fire_event(InvalidOptionYAML(...)), guiding users to fix their config.

The warning message lists the first 10 known flag names to help users identify the correct option.

Since event logger is being setup after flags parsing, the warning needs to be deferred to be shown after event logger is setup for fire_event to work properly here.

Credits to @chinar-amrutkar for the Original PR

Checklist

  • I have read the contributing guide and understand what's expected of me.
  • I have run this code in development, and it appears to resolve the stated issue.
  • This PR includes tests, or tests are not required or relevant for this PR.
  • This PR has no interface changes (e.g., macros, CLI, logs, JSON artifacts, config files, adapter interface, etc.) or this PR has already received feedback and approval from Product or DX.
  • This PR includes type annotations for new and modified functions.

@cla-bot cla-bot Bot added the cla:yes label Apr 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 95.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.32%. Comparing base (d0011b2) to head (e37d875).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12842      +/-   ##
==========================================
- Coverage   91.32%   91.32%   -0.01%     
==========================================
  Files         203      203              
  Lines       25981    26000      +19     
==========================================
+ Hits        23728    23744      +16     
- Misses       2253     2256       +3     
Flag Coverage Δ
integration 88.19% <95.00%> (-0.01%) ⬇️
unit 65.44% <75.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 65.44% <75.00%> (+<0.01%) ⬆️
Integration Tests 88.19% <95.00%> (-0.01%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sriramr98 sriramr98 changed the title Feat/strict flags Feature - Warn on Unknown Flags Apr 15, 2026
@graciegoheen graciegoheen added the user docs [docs.getdbt.com] Needs better documentation label Apr 15, 2026
Copy link
Copy Markdown
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

Thank you for doing this work! It's exciting to get this addressed 🚀

I do think we need to do some more work before we get this out though. As is, we're using the deprecations module to buffer and fire a non deprecation. I assume we're buffering because the event manager isn't set up at the time this event would be normally fired? Interestingly, @aahel is also working on deferring events, but notably that system would require that the event manager be in place (dbt-labs/dbt-common#361).

I think there are really 4 solutions

  1. Make the warning a deprecation, fully set up a real deprecation event, and then use the existing deprecations.buffer
  2. Find away to move the instantiation of the event manager forward in time
  3. Move the logic for checking on unknown flags later in the execution when the event manager has been instantiated
  4. Split out the "buffering" logic out of deprecations module into an event_buffering module

@sriramr98 sriramr98 requested a review from a team as a code owner April 16, 2026 11:45
@sriramr98
Copy link
Copy Markdown
Contributor Author

sriramr98 commented Apr 16, 2026

I think this can be considered a deprecation since using unknown flags will error out in the future when we toggle the flag. However, it ties the warning to the deprecation lifecycle which may not be desired.

Option 4 is also good which can be used to buffer events. What do you suggest between these two @QMalcolm ?

FYI @graciegoheen

@sriramr98
Copy link
Copy Markdown
Contributor Author

@QMalcolm I've pushed some new changes to introduce a behaviour flag that'll raise errors when it finds an unknown flag.

@QMalcolm
Copy link
Copy Markdown
Contributor

QMalcolm commented Apr 17, 2026

I think this can be considered a deprecation since using unknown flags will error out in the future when we toggle the flag. However, it ties the warning to the deprecation lifecycle which may not be desired.

@sriramr98 why would tying it to the deprecation lifecycle not be desired?

@sriramr98
Copy link
Copy Markdown
Contributor Author

sriramr98 commented Apr 19, 2026

@QMalcolm The way I see it, deprecation is something that was once valid/supported is being phased out. Unknown flags were never valid, we were just ignoring them. There's nothing being "deprecated" here. It's adding validation that was always missing.

On the other hand, maybe it was supported for custom use cases and is being "deprecated" here in which case, making this a deprecation is the right choice.

This might be a NIT and we should be good to make this a deprecation. This was just a thought lingering in me

@QMalcolm
Copy link
Copy Markdown
Contributor

What do you suggest between these two @QMalcolm?

@sriramr98 I think, given this will be converted to an error in the future, we should make it a deprecation, i.e. Option 1. Though it might feel weird making it a deprecation in some regard (it wasn't accessible), we did the same with "custom keys on objects". I.e. we deprecated the custom key in the following yaml

models
  - name: my_model
    description: describing my model
    custom_key: my custom stuff

Such custom_key's prior to the deprecation, just got silently dropped ignored, the same that is happening with the custom flags. Additionally, making it a deprecation is the "least" work 😂 Not saying that is the reason we should do it that way, but it is a nice advantage.

@sriramr98
Copy link
Copy Markdown
Contributor Author

@QMalcolm the deprecation warning is added

Copy link
Copy Markdown
Contributor

@QMalcolm QMalcolm left a comment

Choose a reason for hiding this comment

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

Two things to handle

  1. What do we want to do with require_no_unknown_flags behavior flag
  2. We should bump the minimum version of dbt-protos in core/pyproject.toml to be the a version that includes the new event.
    • We often forget to bump this. I definitely have in the past 🫠 It can cause problems in OSS because on a non-fresh install they might retain an earlier version of dbt-protos if we don't bump it

require_sql_header_in_test_configs: bool = False
support_custom_ref_kwargs: bool = False
require_corrected_analysis_fqns: bool = False
require_no_unknown_flags: bool = False
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It doesn't appear we're using this anywhere anymore? Probably just an oversight. If we want to use this, we should edit the logic in project.py to raise an exception instead of buffering the deprecation. If we don't want to use it then we should drop it. I'm fine with either outcome 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We are using it to raise an error if it's set @QMalcolm

Image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🤦🏻 I can't read today. Time for more coffee. Sorry about that 😞

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So it's just the the package bump then

@sriramr98
Copy link
Copy Markdown
Contributor Author

I just realized we might need to re-think this implementation. There are a couple drawbacks to this implementation.

  1. This change only validates against ProjectFlags which are dbt-core exclusive flags. These don't consider dbt-adapter flags
  2. Third Party adapters might have their own flags for various reasons which aren't tracked anywhere in dbt. Even if we handle Point 1, customers might run into issues with third-party adapters
  3. It's also possible that dbt packages rely on custom flags.

I think this is much more trickier than anticipated. We might have to go back to the drawing board and re-think this.

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

Labels

cla:yes user docs [docs.getdbt.com] Needs better documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] make flags: list strict

3 participants