GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: add support for context manager in client by atulep · Pull Request #987 · googleapis/gapic-generator-python

This repository was archived by the owner on Aug 25, 2026. It is now read-only.

Conversation

@atulep

@atulep atulep commented Sep 7, 2021

Copy link
Copy Markdown
Contributor

Addresses feature request filed in #575.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Aza Tulepbergenov added 2 commits September 7, 2021 10:58
Aza Tulepbergenov
feat: add support for context manager in client.
fd9148f
Aza Tulepbergenov
chore: remove extra whitespace.
b677108
@atulep
atulep requested a review from a team September 7, 2021 18:04
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Sep 7, 2021
@software-dov
software-dov self-requested a review September 7, 2021 18:10
@atulep atulep linked an issue Sep 7, 2021 that may be closed by this pull request
Feature Request: allow clients to act as context manager and add close() method to cleanup resources #575
Closed
software-dov
software-dov reviewed Sep 7, 2021
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

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, just some nits around testing.

I think it would be good to have some autogenerated unit tests as well so we can keep generated code coverage at 100%.
Maybe something that injects a dummy transport that can tell us that it was told to enter, something like (strawman expressions in the template, use the correct ones :P )

class DummyTransport:
    def __init__(self):
        self.trigger_state = 0
        
    def __enter__(self):
        self.trigger_state = 1
        
    def __exit__(self, *args, **kwargs):
        self.trigger_state = 2
        
client = {{ api.module_name }}.{{ service.client_name }}(transport=DummyTransport())
assert c.transport.trigger_state == 0
with client:
    assert c.transport.trigger_state == 1
    
assert c.transport.trigger_state == 2

And then associated mox tests for the grpc and rest transport enter/exit methods (I always have to steal mox setup from existing code).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov added 4 commits September 8, 2021 15:44
Aza Tulepbergenov
chore: adds autogenerated unit tests.
15b2533
Aza Tulepbergenov
chore: adds stronger warning.
f5dc286
Aza Tulepbergenov
chore: fixes tests.
c560997
Aza Tulepbergenov
chore: adds auto-generated tests for ads.
983888b
@atulep

atulep commented Sep 13, 2021

Copy link
Copy Markdown
Contributor Author

Looks like golden files need to be updated. I can't get bazel run :update on my Mac due to some weird error related to wrong version of Python. I'm investigating it now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov
chore: updates golden files.
3e49e1a
@atulep
atulep requested a review from busunkim96 September 13, 2021 21:05
software-dov
software-dov reviewed Sep 14, 2021
View reviewed changes

@software-dov software-dov left a comment

Copy link
Copy Markdown
Contributor

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, just a few more obnoxious nitpicking comments :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov
chore: refactor.
b00a6a6
software-dov
software-dov reviewed Sep 14, 2021
View reviewed changes
Comment thread gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov
chore: refactor.
77d92c7
@busunkim96
busunkim96 requested a review from tswast September 16, 2021 15:08
busunkim96
busunkim96 approved these changes Sep 16, 2021
View reviewed changes

@busunkim96 busunkim96 left a comment

Copy link
Copy Markdown
Contributor

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.

Thank you for implementing this!

CC @tswast @nicain I think both of you were interested in this feature, PTAL if you have a moment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
tseaver
tseaver reviewed Sep 16, 2021
View reviewed changes
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

tswast
tswast reviewed Sep 16, 2021
View reviewed changes
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ncclementi ncclementi mentioned this pull request Sep 16, 2021
Initial read_gbq support coiled/dask-bigquery#4
Merged
Aza Tulepbergenov
feat: adds close() to transport and ctx to async client.
4707af5
@atulep

atulep commented Sep 23, 2021

Copy link
Copy Markdown
Contributor Author

@lidizheng PTAL async client

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lidizheng
lidizheng reviewed Sep 23, 2021
View reviewed changes

@lidizheng lidizheng left a comment

Copy link
Copy Markdown
Contributor

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.

The added context manager method looks good, just one minor comment.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov
feat: adds close method and removes ctx from transport in ads.
a136e61
@atulep

atulep commented Sep 24, 2021

Copy link
Copy Markdown
Contributor Author

@software-dov @tseaver @tswast @busunkim96 PTAL. I've addressed all your comments.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Aza Tulepbergenov added 2 commits September 27, 2021 11:25
Aza Tulepbergenov
chore: adds warning infobox to docstring.
3ab1200
Aza Tulepbergenov
chore: updates integration tests.
db48daf
tswast
tswast reviewed Sep 27, 2021
View reviewed changes
Comment thread gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...on/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ation/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ation/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...ration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py Outdated
def close(self):
"""Closes resources associated with the transport.

:: warning::

@tswast tswast Sep 27, 2021

Copy link
Copy Markdown

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.

Suggested change
:: warning::
.. warning::

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
software-dov
software-dov approved these changes Sep 28, 2021
View reviewed changes
Aza Tulepbergenov and others added 2 commits September 30, 2021 10:38
Aza Tulepbergenov
chore: fixes typo.
73f162c
@atulep
Merge branch 'master' into master
d169bc2
@atulep
atulep merged commit 4edabcf into googleapis:master Oct 4, 2021
This was referenced Jan 18, 2022
chore(master): release reverted #1133
Merged
chore(master): release 0.40.0 #1138
Closed
chore(master): release 0.39.1 #1146
Closed
This was referenced Jan 26, 2022
chore(main): release 0.39.1 #1160
Closed
chore(main): release 0.39.1 #1162
Closed
chore(main): release 0.61.0 #1163
Merged
@parthea parthea mentioned this pull request Oct 21, 2023
[BigQuery Data Transfer Service, all GAPIC clients]: provide a close() method and context manager to clean up client-owned resources googleapis/google-cloud-python#9457
Closed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

5 more reviewers
@tseaver tseaver tseaver left review comments
@tswast tswast tswast left review comments
@lidizheng lidizheng lidizheng left review comments
@busunkim96 busunkim96 busunkim96 approved these changes
@software-dov software-dov software-dov approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Feature Request: allow clients to act as context manager and add close() method to cleanup resources

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@atulep @tseaver @tswast @software-dov @lidizheng @busunkim96
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.