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
Add flyway variables support via placeholder templater #4026
Conversation
Codecov ReportBase: 100.00% // Head: 100.00% // No change to project coverage 👍
Additional details and impacted files@@ Coverage Diff @@
## main #4026 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 190 190
Lines 14585 14585
=========================================
Hits 14585 14585
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]: | |||
# Disable interpolation so we can load macros | |||
kw: Dict = {} | |||
kw["interpolation"] = None | |||
config = configparser.ConfigParser(**kw) | |||
config = configparser.ConfigParser(delimiters="=", **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this added?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the configparser doc, "The first occurrence of a delimiting substring on a line is considered a delimiter" and it assumes both ':' and '=' to be delimiters by default. This would mean that the defining a key called "flyway:database = test_db_name" would split key="flyway" and val="database=test_db_name" :(
I see that all our keys use '=' as delimiter and ':' is only used in section names hence made this change. But, If there's a better way to not impose this globally, pls do let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears the current tests don't test for this change. See my comment on test/fixtures/templater/placeholder_flyway_var/placeholder_flyway_var_a.sql
for a suggestion on how to test it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned adding another test. Will any of your tests fail if this delimiters
change is removed? I think it's important to have a test for this.
@@ -0,0 +1,5 @@ | |||
USE ${flyway:database}.test_schema; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any mention of flyway
in the CI output. Perhaps you need to change something else to make this run? The placeholder
templater tests are in this file: test/core/templaters/placeholder_test.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx, will take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated with a test, pls take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, could u let me know if this fixture is needed - not sure where/how it'd be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently not used because the placeholder templater doesn't have a test that reads from file fixtures. See this jinja
test: https://github.com/sqlfluff/sqlfluff/blob/main/test/core/templaters/jinja_test.py#L568L624
Can you look at adding a similar test for the placeholder templater? This would test the config delimiter change you made in a realistic way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, sorry it took me a while to respond. I had actually written the comment above several days ago, but I forgot to submit the pending comments. Occasionally GitHub confuses me. 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the pointers, I'll have take a look soon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test to config_test.py that should hopefully cover the delimiters codecov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the tests pass, this looks good to me. I'd perhaps like to take a look from my computer (currently on my phone) before merging.
Thanks! |
@barrywhart i've pushed a new commit including adding another test. pls have a look.. |
See my comment about the need to add a config test for the I think 1.4.2 will be released in the next few days. |
@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]: | |||
# Disable interpolation so we can load macros | |||
kw: Dict = {} | |||
kw["interpolation"] = None | |||
config = configparser.ConfigParser(**kw) | |||
config = configparser.ConfigParser(delimiters="=", **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears the current tests don't test for this change. See my comment on test/fixtures/templater/placeholder_flyway_var/placeholder_flyway_var_a.sql
for a suggestion on how to test it.
@@ -0,0 +1,5 @@ | |||
USE ${flyway:database}.test_schema; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's currently not used because the placeholder templater doesn't have a test that reads from file fixtures. See this jinja
test: https://github.com/sqlfluff/sqlfluff/blob/main/test/core/templaters/jinja_test.py#L568L624
Can you look at adding a similar test for the placeholder templater? This would test the config delimiter change you made in a realistic way.
@@ -302,7 +302,7 @@ def _get_config_elems_from_file(cls, fpath: str) -> List[ConfigElemType]: | |||
# Disable interpolation so we can load macros | |||
kw: Dict = {} | |||
kw["interpolation"] = None | |||
config = configparser.ConfigParser(**kw) | |||
config = configparser.ConfigParser(delimiters="=", **kw) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned adding another test. Will any of your tests fail if this delimiters
change is removed? I think it's important to have a test for this.
@@ -306,6 +322,8 @@ def test__templater_raw(): | |||
"numeric_dollar_with_braces_and_string", | |||
"percent", | |||
"ampersand", | |||
"flyway_var", | |||
"flyway_var", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does flyway_var
appear twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw some warning to the effect that ids
list has less elements than the test sql's list
____________________________________________ ERROR collecting test/core/templaters/placeholder_test.py ____________________________________________ In test__templater_param_style: 17 parameter sets specified, with different number of ids: 16
I can remove and retest if above can be ignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting addition of a test for the =
delimiter
added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I temporarily removed the delimiters
addition and verified that your new test fails. This will prevent future maintainers from simply removing that change and thinking it's safe because no tests fail.
Unfortunately, the new release happened earlier today, so this will have to wait for the next release (usually 2-4 weeks apart).
sounds good, thx! |
Brief summary of the change made
Proposed solution for #4025
Are there any other side effects of this change that we should be aware of?
Pull Request checklist
Please confirm you have completed any of the necessary steps below.
Included test cases to demonstrate any code changes, which may be one or more of the following:
.yml
rule test cases intest/fixtures/rules/std_rule_cases
..sql
/.yml
parser test cases intest/fixtures/dialects
(note YML files can be auto generated withtox -e generate-fixture-yml
).test/fixtures/linter/autofix
.Added appropriate documentation for the change.
Created GitHub issues for any relevant followup/future enhancements if appropriate.