kaizendorks / pymongo_inmemory

A mongo mocking library with an ephemeral MongoDB running in memory.
MIT License
39 stars 13 forks source link

boolean environment variables not parsed correctly #82

Closed rkingsbury closed 1 year ago

rkingsbury commented 1 year ago

Describe the bug

Setting PYMONGOIM__USE_LOCAL_MONGOD to either True or False results in the log message

WARNING - Using local mongod instance

This occurs because the variable, whether set to True or False, is parsed as a string by os.environ.get at this line, leading to the unexpected behavior that any attempt by the user to set this variable will result in it being evaluated to True.

To Reproduce

export PYMONGOIM__USE_LOCAL_MONGOD=False
python
>>> import os
>>> os.environ.get('PYMONGOIM__USE_LOCAL_MONGOD')
'False'
>>> not os.environ.get('PYMONGOIM__USE_LOCAL_MONGOD')
False
ekarademir commented 1 year ago

This is a very nice catch and a lesson I keep forgetting. It should have been a string comparison to 'true'.

rkingsbury commented 1 year ago

A similar problem may apply to PYMONGOIM__MONGO_VERSION which I believe is parsed to a string instead of a numeric value

ekarademir commented 1 year ago

A similar problem may apply to PYMONGOIM__MONGO_VERSION which I believe is parsed to a string instead of a numeric value

For this str is fine, because this value is being parsed into SemVer down the line, hence, value provided can include dots.