Skip to content

Commit

Permalink
Merge branch 'defect-1483-task-status'
Browse files Browse the repository at this point in the history
  • Loading branch information
John Glover committed Dec 7, 2011
2 parents 8df63fc + 520959c commit b80162d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
9 changes: 6 additions & 3 deletions ckan/logic/action/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ def user_update(context, data_dict):

def task_status_update(context, data_dict):
model = context['model']
session = model.meta.create_local_session()
context['session'] = session

user = context['user']
id = data_dict.get("id")
schema = context.get('schema') or default_task_status_schema()
Expand All @@ -382,13 +385,13 @@ def task_status_update(context, data_dict):
data, errors = validate(data_dict, schema, context)

if errors:
model.Session.rollback()
session.rollback()
raise ValidationError(errors, task_status_error_summary(errors))

task_status = task_status_dict_save(data, context)

if not context.get('defer_commit'):
model.Session.commit()
session.commit()
session.close()
return task_status_dictize(task_status, context)

def task_status_update_many(context, data_dict):
Expand Down
3 changes: 2 additions & 1 deletion ckan/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def init_model(engine):
'''Call me before using any of the tables or classes in the model'''
meta.Session.remove()
meta.Session.configure(bind=engine)
meta.create_local_session.configure(bind=engine)
meta.engine = engine
meta.metadata.bind = engine
# sqlalchemy migrate version table
Expand All @@ -45,7 +46,7 @@ def init_model(engine):
except sqlalchemy.exc.NoSuchTableError:
pass



class Repository(vdm.sqlalchemy.Repository):
migrate_repository = ckan.migration.__path__[0]
Expand Down
29 changes: 13 additions & 16 deletions ckan/model/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,19 @@ def after_rollback(self, session):
# SQLAlchemy database engine. Updated by model.init_model()
engine = None

if sqav.startswith("0.4"):
# SQLAlchemy session manager. Updated by model.init_model()
Session = scoped_session(sessionmaker(
autoflush=False,
transactional=True,
extension=[CkanSessionExtension(),
extension.PluginSessionExtension()],
))
else:
Session = scoped_session(sessionmaker(
autoflush=False,
autocommit=False,
expire_on_commit=False,
extension=[CkanSessionExtension(),
extension.PluginSessionExtension()],
))
Session = scoped_session(sessionmaker(
autoflush=False,
autocommit=False,
expire_on_commit=False,
extension=[CkanSessionExtension(), extension.PluginSessionExtension()],
))

create_local_session = sessionmaker(
autoflush=False,
autocommit=False,
expire_on_commit=False,
extension=[CkanSessionExtension(), extension.PluginSessionExtension()],
)

#mapper = Session.mapper
mapper = orm.mapper
Expand Down

0 comments on commit b80162d

Please sign in to comment.