Skip to content

datastore.(set|get)_default_connection() is a bit misleading #841

Description

@jgeewax

I think set_default_connection is a bit misleading, in that it "tries to create a connection from the environment"... To put this in pseudo-code:

defget_default_connection():
connection=<somepre-loadedconnectionalreadystored>ifnotconnection:
connection=<createaconnectionsomehowfromtheenvironment>ifnotconnection:
connection=<createaconnectionfromtheenvironmentanotherway>ifnotconnection:
raiseEnvironmentError('Connection cannot be inferred from the environment :(')
returnconnectiondefset_default_connection(connection=None):
<somesafeplacetostoreaconnection>=connection# Yes, this could be None.

The idea being...

  • set_default_connection() sets a variable, that's all.
  • get_default_connection() goes through a list of possible ways to get a connection, raising an exception when we can't get one...

What we have today is:

  • set_default_connection() sets a variable and tries to come up with a magical connection from the environment if possible.
  • get_default_connection() only returns the variable

I'm sure this will be subject to a bunch of debate, but having a getter method also doing some setting seems really misleading to me.

Metadata

Metadata

Assignees

Labels

type: questionRequest for information or clarification. Not an issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions