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

Case sensitivity #193

Merged
merged 4 commits into from
Jan 3, 2024
Merged

Case sensitivity #193

merged 4 commits into from
Jan 3, 2024

Conversation

dave-connors-3
Copy link
Collaborator

closes #190

As reported, when creating a contract, all column names are currently standardized to lowercase, even if the column was in uppercase in the original yml, leading to unintended duplications/overwriting. This PR adds a step to the Contractor class to maintain the original casing of each of the columns from the yml entry. Anything not defined in yml, but present in the catalog will continue to be lowercased.

I could not figure out a clean way to pass dynamic column content to our pytest fixture in the unit tests, so i created a new model fixture that included the column specifications. I think that's a big code smelly, so open to suggestions.

@nicholasyager nicholasyager added the bug Something isn't working label Jan 2, 2024
Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

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

@dave-connors-3 I've left a few comments. One around cleaning up a print statement, and a couple of recommendations around nitpicky code-smell thoughts. Removing the print statement is the only blocking change in this review.

@@ -15,11 +15,18 @@ def generate_contract(self, model: ModelNode) -> ResourceChange:
"""Generate a ChangeSet that adds a contract to a Model."""
model_catalog = self.project.get_catalog_entry(model.unique_id)

# create a mapping of the column name to its representation in the yml file to maintain the original case
original_case = {column_name.lower(): column_name for column_name in model.columns.keys()}
print(original_case)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might want to clean this print statement up.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

lol i caught this earlier and never pushed smdh

if not model_catalog or not model_catalog.columns:
columns = None
else:
columns = [
{"name": name.lower(), "data_type": value.type.lower()}
{
"name": original_case.get(name.lower()) or name.lower(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is totally correct and likely ideal due to readability! Another way of doing this is through the use of get's second argument.

original_case.get(name.lower(), name.lower())

Comment on lines 82 to +91
@pytest.fixture
def change(project, model) -> ResourceChange:
contractor = Contractor(project=project)
return contractor.generate_contract(model)


@pytest.fixture
def all_cap_model_change(project, all_cap_model) -> ResourceChange:
contractor = Contractor(project=project)
return contractor.generate_contract(all_cap_model)
Copy link
Collaborator

@nicholasyager nicholasyager Jan 2, 2024

Choose a reason for hiding this comment

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

This isn't terrible, but I see what you mean by code smell. I suspect that this fixture could follow a factory pattern instead, in which the fixture returns a function that itself generates or returns models that have different capitalization configurations.

Copy link
Collaborator

@nicholasyager nicholasyager left a comment

Choose a reason for hiding this comment

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

@dave-connors-3 these changes are both necessary and sufficient. ✅

@dave-connors-3 dave-connors-3 merged commit eb92e80 into main Jan 3, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

column operations do not maintain case sensitivity
2 participants