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 — set_default_project living inside each service module is confusing · Issue #838 · googleapis/google-cloud-python

set_default_project living inside each service module is confusing #838

New issue
Copy link
New issue
Copy link
Closed
Closed
set_default_project living inside each service module is confusing#838
Copy link
Assignees
dhermes
Labels
api: core

Description

@jgeewax
jgeewax
opened on Apr 17, 2015
Issue body actions

Looks like inside each service module (let's say datastore and pubsub) we import _helpers.set_default_project.

If that's the case, I'd expect the following code snippet to have different projects set for the different services:

from gcloud import datastore, pubsub
datastore.set_default_project('datastore-project')
pubsub.set_default_project('pubsub-project')

assert 'datastore-project' == datastore.get_default_project()
assert 'pubsub-project' == pubsub.get_default_project()

If that's not the case, we need to figure out some other way of doing this... maybe moving the helper method into the top level as gcloud.set_default_project()...

Activity

Next
  1. jgeewax
    added
    api: core
    on Apr 17, 2015
  2. jgeewax
    added this to the This milestone has been deleted milestone on Apr 17, 2015
  3. dhermes commented on Apr 17, 2015

    @dhermes
    dhermes
    on Apr 17, 2015
    Contributor
    More actions

    @jgeewax It seems you're just concerned with the fact that the method lives in each sub-package?

    We discussed the idea of a library-wide default project with you at a standup meeting and you signed off on it. (@tseaver noted this immediately after.)

    The method is only defined in one place gcloud._helpers but it is imported as a public method (i.e. no import ... as rename) in both storage.__init__ and pubsub.__init__.

    This is so that we can call it from set_defaults() in each of those packages.


    1. An easy (partial) way to address your concern will just be
    from gcloud._helpers import set_default_project as _set_default_project 
    1. A remaining issue will be "confusion" if someone does something explicit / declarative like
    from gcloud import pubsub
    from gcloud import storage
    ...
    pubsub.set_defaults(connection=conn2, project='proj2')
    storage.set_defaults(connection=conn1, project='proj1')

    because the value 'proj1' will become the global (not just pubsub only) default. A "wrong global" would not be that big an issue for storage since the project is seldom used. It would be a huge issue for pubsub since a project is sent in every request.
    3. We could address the above point by either removing project= from set_defaults or by making the default project local to each sub-package.

  4. jgeewax commented on Apr 17, 2015

    @jgeewax
    jgeewax
    on Apr 17, 2015
    ContributorAuthor
    More actions

    You're correct in the case of (2) -- we expose the method under each service, but it's not specific to the service. That's pretty confusing to me -- I'd expect a separate default for the service in which I called the method...

    Option 4 might be to have a gcloud.get_default_project() and then service specific ones that override the global one... But that's getting pretty tricky...

  5. dhermes commented on Apr 17, 2015

    @dhermes
    dhermes
    on Apr 17, 2015
    Contributor
    More actions

    Yeah I had thought of Option 4. It would be a lot of code for a non-crucial feature.

  6. jgeewax commented on Apr 29, 2015

    @jgeewax
    jgeewax
    on Apr 29, 2015
    ContributorAuthor
    More actions

    It seems you're just concerned with the fact that the method lives in each sub-package?

    This is correct.

    This brings about a further issue that I'm curious about:

    from gcloud import pubsub
    from gcloud import storage
    ...
    pubsub.set_defaults(connection=conn2, project='proj2')
    storage.set_defaults(connection=conn1, project='proj1')

    What is the default connection used when talking to Pub Sub here? I think it's conn1 (even though I set the "pubsub connection" to be conn2)...

    So:

    1. Why do we need set_defaults as separate methods inside each module?
    2. If we don't have a great reason, are there any objections to just... pulling it out?

    If we had the defaults pulled out:

    import gcloud
    gcloud.set_defaults(connection=conn, project='project')
    # No way to set any 'module-specific' defaults.

    Assigning back to you to take a look :)

  7. jgeewax
    assigned
    jgeewax
    and
    dhermes
    and unassigned
    jgeewax
    on Apr 29, 2015
  8. dhermes commented on Apr 29, 2015

    @dhermes
    dhermes
    on Apr 29, 2015
    Contributor
    More actions

    We don't have any cross-package objects / data other than the project string. The connections in each sub-package are only able to talk to their own service.

  9. jgeewax commented on Apr 29, 2015

    @jgeewax
    jgeewax
    on Apr 29, 2015
    ContributorAuthor
    More actions

    Yep, so pubsub.set_defaults() does the exact same thing as storage.set_defaults()... Is there a reason for that? Legacy?

  10. dhermes commented on Apr 29, 2015

    @dhermes
    dhermes
    on Apr 29, 2015
    Contributor
    More actions

    No. They both set a global project (which I am uneasy with and is the point of this) but the connection is only package specific.

    The interface is the same but the internals are different.

  11. jgeewax commented on Apr 29, 2015

    @jgeewax
    jgeewax
    on Apr 29, 2015
    ContributorAuthor
    More actions

    OK so the connection is package specific... Totally misread.

    So, Option 3 above has two pieces:

    1. remove the project= from the defaults
    2. make project specific to a connection

    Do you have a preference?

  12. dhermes commented on Apr 29, 2015

    @dhermes
    dhermes
    on Apr 29, 2015
    Contributor
    More actions

    "make project specific to a connection" makes sense for pubsub but not for storage. In storage only 2 out of 34 API requests use the project.

    I was a fan of having the default project by package specific, but @tseaver was more enthusiastic about having it be a global than I was about having it be package specific. I can be persuaded either way.

  13. dhermes commented on Aug 27, 2015

    @dhermes
    dhermes
    on Aug 27, 2015
    Contributor
    More actions

    This is moot in the presence of client pattern

  14. 3 remaining items

  15. parthea
    added a commit that references this issue on Aug 21, 2025

    Fix: Add response object to any append rows requests exception (#838)

    a32f758
  16. parthea
    added 2 commits that reference this issue on Sep 16, 2025

    Fix: Add response object to any append rows requests exception (#838)

    f7ab856

    fix: `to_gbq` uses `default_type` for ambiguous array types and struc…

    6586cf9
  17. parthea
    added 5 commits that reference this issue on Nov 24, 2025

    chore: use trim_blocks and lstrip_blocks for jinja templates (#838)

    bc72466

    chore(main): release 2.25.2 (#838)

    f794f35

    chore: Revert autogenerated changes which have not been released (#838)

    53df06f

    docs(CONTRIBUTING): Note the need for Redis/Memcached env vars in tes…

    21820d8

    test: address comments for downscoping tests (#838)

    f552ca1
  18. parthea
    added 6 commits that reference this issue on Mar 2, 2026

    chore(python): add support for python 3.11 [autoapprove] (#838)

    4637d22

    chore(deps): update dependency google-cloud-bigquery to v2.23.2 (#838)

    668839e

    chore: [autoapprove] Update `black` and `isort` to latest versions (#838

    d303b47

    chore(deps): update opentelemetry-python monorepo to v1.40.0 (#838)

    7365312

    chore(main): release 2.6.0 (#838)

    2b456a0

    feat: support requiest options in !autocommit mode (#838)

    d93aa8a
  19. parthea
    added a commit that references this issue on Sep 8, 2026

    docs: migrate code from googleapis/python-bigquery (#18303)

    23f9a74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.