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

Fix bug affecting sanitization version of sync tables #15885

Merged

Conversation

jgoizueta
Copy link
Contributor

See https://app.clubhouse.io/cartoteam/story/108990

In connector syncs, when sanitization is (redundantly, see #15231 (comment)) applied, the applied sanitization version was being fetched by a new Table object for which a new, unsaved DataImport was generated, and that data import was used to obtain the sanitization version. Until a DataImport is actually created, the version defaults to the legacy one, so that's we were getting

@@ -268,8 +268,7 @@ def import_cleanup(schema_name, table_name)
# but is kept because there may be existing syncs for which this double sanitization
# (version 1 sanitization which wasn't idemponent) had the effect of altering some
# satinizated names (e.g. __1 -> _1).
table = ::Table.new(name: @table_name, user_id: @user.id)
# we could as well: table = Carto::UserTable.find(@user.tables.where(name: @table_name).first.id).service
table = Carto::UserTable.find(@user.tables.where(name: @table_name).first.id).service
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you replace:

@user.tables.where(name: @table_name).first.id

per:

@user.tables.find_by(name: @table_name).id

It's a bit more idiomatic 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change can affect some users with sync tables and break their visualizations, since column names where uppercase letters have been replaced by underscores will change. But we can prevent the users we know about (in the clubhouse ticket) and I think the alternative, to create a new sanitization version and preserve the odd behaviour in the current one, is worse.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thougt @user.tables returned an AR relationship, but per what I see in the CI log I think i was wrong:

Step #9: undefined method `find_by' for #<#<Class:0x000055f7aaf4eaf0>:0x000055f7aa1d9460>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I had just found that: I tested it in a console and it worked because I had an AR Carto::User, but the tests seem to use some Sequel ::User, and I guess we should cover all bases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to leave the original @user.tables.where(name: @table_name).first.id even if ugly because it seems to work regardless of @user being AR or Sequel, and because we may have more customers affected

This reverts commit 6d1a878.
The reason is that the change didn't work if user was a Sequel
object (::User) rather than an ActiveRecord (Carto::User).
@jgoizueta
Copy link
Contributor Author

Now we have:

@jgoizueta
Copy link
Contributor Author

Step #9: Failures:
Step #9:
Step #9: 1) Carto::Api::VisualizationsController index returns valid information for a user with one table
Step #9: Failure/Error: table1_visualization_hash = table1_visualization.to_hash(
Step #9: NameError:
Step #9: uninitialized constant CartoDB::PermissionPresenter
Step #9: # ./app/models/visualization/presenter.rb:33:in to_poro' Step #9: # ./app/models/visualization/member.rb:317:in to_hash'
Step #9: # ./spec/requests/carto/api/visualizations_controller_spec_part_1.rb:316:in `block (3 levels) in <top (required)>'
Step #9:
Step #9: Finished in 4 minutes 38.93 seconds
Step #9: 105 examples, 1 failure


@jgoizueta jgoizueta merged commit 05b4e98 into master Oct 7, 2020
@jgoizueta jgoizueta deleted the feature/ch108990/geoagro-admin-problem-with-the-field-name branch October 7, 2020 09:55
@thedae thedae mentioned this pull request Nov 6, 2020
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.

2 participants