Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both yaml and yml file extension for project config files #11261

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

morgan-dgk
Copy link

@morgan-dgk morgan-dgk commented Jan 31, 2025

Resolves #5002, #8738

Problem

From relevant faq:

At present, dbt will only search for files with a .yml file extension. In a future release of dbt, dbt will also search for files with a .yaml file extension

This behaviour is potentially confusing to new users and runs against the official recommendations in the yaml faq. I was certainly confused by this when I first started working with dbt and ran into errors finding dbt project configuration fils such as profiles.yaml and dbt_project.yaml.

Solution

Failing tests are currently due to hardcoded file names in assertions where tests are expected to fail.

This PR introduces a new helper function get_yaml_path in the yaml_helper module. Given the path to a stem (i.e the path to a yaml file without any extension), this function attempts to finding a matching yaml file ending in either of the accepted extensions, i.e. .yml or .yaml. If no match is found, an empty string is returned.

So as to minimise the changes required to existing code, I also removed the .yml extension from the relevant constants in the dbt/constants module.

I initially considered implementing this somewhere in dbt_common following previous guidance provided on #5002 but the structure of the project appears to have changed since those comments were made. Additionally, there is some variance in how paths to config files are resolved.

For example, some project file paths are defined as constants whereas profiles.yml is passed directly as a string to os.path.join in profiles.yml. In the majority of cases, the path to project files appears to be passed around as a string, but in tasks/base.py.

Using the new helper function as a wrapper to existing calls to resolve the path for relevant config files seemed the least likely to break existing behaviour.

See also comments on #5002.

2e938d7 is an unrelated change, but I could not get pre-commit hooks to work correctly without this change. I believe the underlying issue relates to changes in metadata lib in python 3.12

Checklist

  • [ x ] I have read the contributing guide and understand what's expected of me.
  • [ x ] 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.
  • [ x ] 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.
  • [ x ] This PR includes type annotations for new and modified functions.

Currently, the `default_language_version` key in .pre-commit-config.yaml
defaults to whatever system version of python3 is available. This can cause
issues when running the flak
@morgan-dgk morgan-dgk requested a review from a team as a code owner January 31, 2025 05:36
Copy link

cla-bot bot commented Jan 31, 2025

Thanks for your pull request, and welcome to our community! We require contributors to sign our Contributor License Agreement and we don't seem to have your signature on file. Check out this article for more information on why we have a CLA.

In order for us to review and merge your code, please submit the Individual Contributor License Agreement form attached above above. If you have questions about the CLA, or if you believe you've received this message in error, please reach out through a comment on this PR.

CLA has not been signed by users: @morgan-dgk

Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

@github-actions github-actions bot added the community This PR is from a community member label Jan 31, 2025
Add new `get_yaml_path` helper to allow handling of both yml and yaml
file extension for dbt project config files (currently `profiles` and
`dbt_project` files).

Small number of failing tests are due to hardcoded references to short
file extension in tests which expected an error to be raised.
@morgan-dgk morgan-dgk force-pushed the feat/support-full-yaml-file-extension branch from 52c61b3 to 5b57156 Compare January 31, 2025 05:40
@cla-bot cla-bot bot added the cla:yes label Jan 31, 2025
@morgan-dgk morgan-dgk marked this pull request as draft January 31, 2025 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes community This PR is from a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CT-462] [Feature] .yaml and .yml extensions are interchangeable for profiles.yml, etc.
1 participant