Skip to content

get_default_session() should be public #2707

Open
@benkehoe

Description

@benkehoe

Currently, DEFAULT_SESSION and setup_default_session() are public members of boto3 module, but the caching _get_default_session() is not. I'd like to see this changed. I often write functions that look like

def my_func(arg1, arg2, session=None):
    if not session:
        session = boto3._get_default_session()

some people write this as

def my_func(arg1, arg2, session=None):
    if not session:
        session = boto3

but this breaks if I'm doing anything other than creating a client.

I can't write the following because it might not be initialized:

def my_func(arg1, arg2, session=None):
    if not session:
        session = boto3.DEFAULT_SESSION

I can't write the following because DEFAULT_SESSION might have been initialized to a custom value already:

def my_func(arg1, arg2, session=None):
    if not session:
        session = boto3.setup_default_session()

I could copy in the logic from _get_default_session() (which only calls setup_default_session() if DEFAULT_SESSION isn't initialized) into each place where I do this, but why make me do that?

There doesn't seem to be any good reason for it to be private, especially given that the fields it operates on are public. I'd ask for the function to be renamed get_default_session() and an alias _get_default_session = get_default_session to be added for backward compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestThis issue requests a feature.p2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions