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: use public 'table_admin_client' property in backups methods #359

Merged
merged 3 commits into from Jul 13, 2021

Conversation

kolea2
Copy link
Collaborator

@kolea2 kolea2 commented Jul 9, 2021

calling _table_admin_client was lazily evaluated and would return a NoneType in cases where table operations were not already done.

@kolea2 kolea2 requested review from a team as code owners July 9, 2021 19:34
@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/python-bigtable API. label Jul 9, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Jul 9, 2021
@kolea2
Copy link
Collaborator Author

kolea2 commented Jul 9, 2021

@crwilcox any ideas on how to reliably test this?

@tseaver tseaver changed the title fix: call table_admin_client in backups methods fix: use public 'table_admin_client' property in backups methods Jul 9, 2021
@tseaver
Copy link
Contributor

tseaver commented Jul 9, 2021

Because a Python property looks just like an attribute, there isn't any good way to distinguish them. You could add a property to the dummy _Client class which returned the value of a different attribute, e.g.:

class _Client(object):
    _different_tac = None

    def __init__(self, project=TestBackup.PROJECT_ID):
        self.project = project
        self.project_name = "projects/" + self.project

    @property
    def table_admin_client(self):
        return self._different_tac

and then populate _different_tac in the tests.

@tseaver
Copy link
Contributor

tseaver commented Jul 9, 2021

I just checked, and there is a mock.PropertyMock which might do, but it is too gnarly to use IMHO.

tseaver
tseaver previously requested changes Jul 9, 2021
tests/unit/test_backup.py Show resolved Hide resolved
@kolea2
Copy link
Collaborator Author

kolea2 commented Jul 12, 2021

Because a Python property looks just like an attribute, there isn't any good way to distinguish them. You could add a property to the dummy _Client class which returned the value of a different attribute, e.g.:

class _Client(object):
    _different_tac = None

    def __init__(self, project=TestBackup.PROJECT_ID):
        self.project = project
        self.project_name = "projects/" + self.project

    @property
    def table_admin_client(self):
        return self._different_tac

and then populate _different_tac in the tests.

@tseaver discussed with @crwilcox, we decided to go with a slightly different approach here. In the backups system test, reset the Client so that we can assert the table admin client object is initialized and returned. I tested this with and without my patch to confirm this works. LMK what you think!

@tseaver
Copy link
Contributor

tseaver commented Jul 12, 2021

@kolea2 I don't think I grok the need for the system test change. If you want to ensure that all the methods which use the table admin client use the property, rather than the attribute, then just setting the same-named attribute on the _Client shim in the unit tests should do the trick: any methods which try to use _table_admin_client will fail.

@crwilcox
Copy link
Contributor

The system test change ensure we start with all lazy-loading reset.

As for testing, the issue is we mock that bit out as best I can tell. The changes @kolea2 made means the mock no longer even has the internal surface, so it def. isn't being called.

@kolea2 kolea2 dismissed tseaver’s stale review July 13, 2021 18:29

per @crwilcox's comment, will leave testing to system.py. We can revisit adding more mocked unit tests if we find it necessary in the future.

@kolea2 kolea2 merged commit bc57c79 into googleapis:master Jul 13, 2021
@kolea2 kolea2 deleted the backups-admin-fix branch July 13, 2021 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/python-bigtable API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants