Skip to content
This repository was archived by the owner on Aug 26, 2021. It is now read-only.

Add mLab MongoDB; complain about several mongo installations #35

Merged
merged 2 commits into from
May 13, 2017
Merged

Add mLab MongoDB; complain about several mongo installations #35

merged 2 commits into from
May 13, 2017

Conversation

vmax
Copy link
Contributor

@vmax vmax commented May 7, 2017

  1. Added mLab
  2. Previously if you had both addons (MongoLab and MongoHQ) if would silently fall back to the latter; now it produces an error message

flask_heroku.py Outdated
mlab_mongo_uri = environ.get('MONGODB_URI')

if sum(1 for uri in (
mongolab_uri, mongohq_uri, mlab_mongo_uri) if uri) > 1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a really obscure way of checking if there is more than one Mongo addon available. I'd suggest using a set intersection, like this:

mongo_addon_vars = set(("MONGOLAB_URI", "MONGOHQ_URL", "MONGODB_URI"))
defined_env_vars = set(var for var, value in os.environ.items() if value) 
defined_mongo_addons = defined_env_vars.intersection(mongo_addon_vars)
if len(defined_mongo_addons) == 1:
    mongo_addon_var = next(iter(defined_mongo_addons))  # This seems to be the only way of getting the element out of the set :(
    mongo_uri = os.environ[mongo_addon_var]
    # parse as normal
elif len(defined_mongo_addons) > 1:
    logger.error("Multiple MongoDB addons enabled. Flask-Heroku cannot determine which to use.")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singingwolfboy actually, it's not, we have pop() https://docs.python.org/3/library/stdtypes.html#set.pop

I'll rework the rest according to your suggestions now

@vmax
Copy link
Contributor Author

vmax commented May 12, 2017

@singingwolfboy I hope now it's less obscure — please have a look ;)

@singingwolfboy singingwolfboy merged commit 98e03c0 into heroku-python:master May 13, 2017
@singingwolfboy
Copy link
Contributor

Thanks!

@vmax
Copy link
Contributor Author

vmax commented May 13, 2017

@singingwolfboy I believe for it to be available for general public you may want to bump up the package version in setup.py

@vmax vmax deleted the mlab-mongodb branch May 13, 2017 15:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants