Skip to content
Snippets Groups Projects
Commit 6b4f6fa1 authored by Anton Sarukhanov's avatar Anton Sarukhanov
Browse files

Remove trash in models and requirements.

parent cf059474
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,6 @@ class Model(db.Model):
@classmethod
def get_or_create(self, session, create_method='', create_method_kwargs=None, **kwargs):
""" Try to find an existing object filtering by kwargs. If not found, create. """
keys = [k.name for k in inspect(self).primary_key]
inspector = reflection.Inspector.from_engine(db.engine)
keys = list(chain.from_iterable([i['column_names'] for i in
inspector.get_indexes(inspect(self).mapped_table)]))
......@@ -38,12 +37,6 @@ class Model(db.Model):
filter_args = {arg: kwargs[arg] for arg in kwargs if arg in keys}
try:
return session.query(self).filter_by(**filter_args).one()
except MultipleResultsFound:
raise Exception("{0} matches in get_or_create. This should never happen."
" More primary keys are probably needed for some models."
"\nkwargs = {1}\nkeys = {2}\nfilter_args = {3}"
.format(session.query(self).filter_by(**filter_args).count(),
kwargs, keys, filter_args))
except NoResultFound:
kwargs.update(create_method_kwargs or {})
new = getattr(self, create_method, self)(**kwargs)
......
......@@ -13,19 +13,13 @@ aiohttp==0.18.4
alembic==0.8.3
amqp==1.4.7
anyjson==0.3.3
backports-abc==0.4
billiard==3.3.0.21
celery==3.1.19
chardet==2.3.0
itsdangerous==0.24
kombu==3.0.29
line-profiler==1.0
lxml==3.4.4
psutil==3.3.0
psycopg2==2.6.1
python-editor==0.4
pytz==2015.7
redis==2.10.5
requests==2.8.1
requests-futures==0.9.5
tornado==4.3
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment