Improper handling of session API
brianbruggeman opened this issue · comments
In setting up a py.test session fixture, I ran into an issue where Alchy does not properly handle arguments passed from SQLAlchemy.
> session.add(model)
tests/test_models.py:17:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../.envs/platform/lib/python3.5/site-packages/sqlalchemy/orm/scoping.py:157: in do
return getattr(self.registry(), name)(*args, **kwargs)
../../../.envs/platform/lib/python3.5/site-packages/sqlalchemy/util/_collections.py:1025: in __call__
val = self.registry.value = self.createfunc()
../../../.envs/platform/lib/python3.5/site-packages/alchy/manager.py:241: in create_session
return self.session_class(self, **options)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <alchy.session.Session object at 0x10ddaf908>, manager = <alchy.manager.Manager object at 0x10c512f28>, options = {'binds': {}}, bind = <sqlalchemy.engine.base.Connection object at 0x10dda2a20>
def __init__(self, manager, **options):
self.manager = manager
bind = options.pop('bind', manager.engine)
super(Session, self).__init__(bind=bind,
binds=manager.binds_map,
> **options)
E TypeError: __init__() got multiple values for keyword argument 'binds'
../../../.envs/platform/lib/python3.5/site-packages/alchy/session.py:22: TypeError
The easy fix here is to update __init__
within the Session class to pop off the extraneous options. That said, I am not sure what the ramifications are of ignoring the binds
value. Therefore, my proposed solution is as follows:
def __init__(self, manager, **options):
self.manager = manager
bind = options.pop('bind', manager.engine)
binds = options.pop('binds', {}) or manager.binds_map
super(Session, self).__init__(bind=bind,
binds=binds,
**options)
The proposed solution looks fine to me. Good catch! 👍
If you want to submit a PR, I'll merge it in.
So, I ended up with some issues with the py.test environment and ultimately I had to change quite a bit to get the tests to run... Would you be okay if I also expanded the testing interface?
You're talking about py.test environment for alchy? What is it that you had to change and what is it you propose to expand?
I haven't had any issues getting tests to run on my end so curious what kind if issues you are running into.
Fix released as v2.2.2
: https://pypi.python.org/pypi/alchy/2.2.2