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(cli): add impersonate_user to db import #29522

Merged
merged 5 commits into from
Aug 12, 2024

Conversation

chessman
Copy link
Contributor

@chessman chessman commented Jul 9, 2024

SUMMARY

When importing a directory using superset import-directory command, it should respect the impersonate_user flag specified in the database yaml definition.

TESTING INSTRUCTIONS

Import a database that supports this flag and verify that this flag is enabled.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot bot added the data:connect Namespace | Anything related to db connections / integrations label Jul 9, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

Makes me wonder whether other fields may get lost while doing export/import round trips.

@rusackas
Copy link
Member

rusackas commented Aug 5, 2024

I believe @yousoph and @eschutho are taking stock of bits that are not part of import/export but ought to be.

@rusackas rusackas requested a review from eschutho August 5, 2024 16:30
Copy link

codecov bot commented Aug 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.70%. Comparing base (76d897e) to head (a5ed1e2).
Report is 580 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #29522       +/-   ##
===========================================
+ Coverage   60.48%   83.70%   +23.21%     
===========================================
  Files        1931      527     -1404     
  Lines       76236    38053    -38183     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    31851    -14263     
+ Misses      28017     6202    -21815     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 49.02% <100.00%> (-0.15%) ⬇️
javascript ?
mysql 76.78% <100.00%> (?)
postgres 76.86% <100.00%> (?)
presto 53.57% <100.00%> (-0.24%) ⬇️
python 83.70% <100.00%> (+20.21%) ⬆️
sqlite 76.34% <100.00%> (?)
unit 60.36% <100.00%> (+2.73%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -171,6 +171,7 @@ class Database(Model, AuditMixinNullable, ImportExportMixin): # pylint: disable
"allow_dml",
"allow_file_upload",
"extra",
"impersonate_user"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"impersonate_user"
"impersonate_user",

@eschutho
Copy link
Member

eschutho commented Aug 5, 2024

Can we add a unit test with the new param? Here's an example in tests/unit_tests/databases/commands/importers/v1/import_test.py

def test_import_database_with_user_impersonation(
    mocker: MockerFixture,
    session: Session,
) -> None:
    """
    Test importing a database that is managed externally.
    """
    from superset import security_manager
    from superset.commands.database.importers.v1.utils import import_database
    from superset.models.core import Database
    from tests.integration_tests.fixtures.importexport import database_config

    mocker.patch.object(security_manager, "can_access", return_value=True)

    engine = db.session.get_bind()
    Database.metadata.create_all(engine)  # pylint: disable=no-member

    config = copy.deepcopy(database_config)
    config["impersonate_user"] = True

    database = import_database(config)
    assert database.impersonate_user is True
    ```

@rusackas
Copy link
Member

rusackas commented Aug 8, 2024

Approving CI. Ping me if it passes and needs a merge!

@chessman
Copy link
Contributor Author

chessman commented Aug 8, 2024

@rusackas This error looks unrelated to my changes.

>       conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
E       sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "host1" to address: Temporary failure in name resolution
E       
E       (Background on this error at: https://sqlalche.me/e/14/e3q8)

@rusackas
Copy link
Member

Running CI. 🤞 Ping me if it turns green :D

@chessman
Copy link
Contributor Author

@rusackas it's green!

@eschutho eschutho merged commit 050c6da into apache:master Aug 12, 2024
37 checks passed
@eschutho
Copy link
Member

Thanks @chessman!

@chessman chessman deleted the add-impersonate-user branch August 13, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:connect Namespace | Anything related to db connections / integrations size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants