本文整理汇总了Python中sqlalchemy.orm.make_transient函数的典型用法代码示例。如果您正苦于以下问题:Python make_transient函数的具体用法?Python make_transient怎么用?Python make_transient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_transient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check_pdf_urls
def check_pdf_urls(pdf_urls):
for url in pdf_urls:
make_transient(url)
# free up the connection while doing net IO
safe_commit(db)
db.engine.dispose()
req_pool = get_request_pool()
checked_pdf_urls = req_pool.map(get_pdf_url_status, pdf_urls, chunksize=1)
req_pool.close()
req_pool.join()
row_dicts = [x.__dict__ for x in checked_pdf_urls]
for row_dict in row_dicts:
row_dict.pop('_sa_instance_state')
db.session.bulk_update_mappings(PdfUrl, row_dicts)
start_time = time()
commit_success = safe_commit(db)
if not commit_success:
logger.info(u"COMMIT fail")
logger.info(u"commit took {} seconds".format(elapsed(start_time, 2)))
示例2: test_deleted_flag
def test_deleted_flag(self):
users, User = self.tables.users, self.classes.User
mapper(User, users)
sess = sessionmaker()()
u1 = User(name='u1')
sess.add(u1)
sess.commit()
sess.delete(u1)
sess.flush()
assert u1 not in sess
assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
sess.rollback()
assert u1 in sess
sess.delete(u1)
sess.commit()
assert u1 not in sess
assert_raises(sa.exc.InvalidRequestError, sess.add, u1)
make_transient(u1)
sess.add(u1)
sess.commit()
eq_(sess.query(User).count(), 1)
示例3: new_version
def new_version(self, session):
# convert to an INSERT
make_transient(self)
self.id = None
# history of the 'elements' collection.
# this is a tuple of groups: (added, unchanged, deleted)
hist = attributes.get_history(self, "elements")
# rewrite the 'elements' collection
# from scratch, removing all history
attributes.set_committed_value(self, "elements", {})
# new elements in the "added" group
# are moved to our new collection.
for elem in hist.added:
self.elements[elem.name] = elem
# copy elements in the 'unchanged' group.
# the new ones associate with the new ConfigData,
# the old ones stay associated with the old ConfigData
for elem in hist.unchanged:
self.elements[elem.name] = ConfigValueAssociation(
elem.config_value
)
示例4: detach
def detach(self):
if self in g.db:
g.db.expunge(self)
make_transient(self)
self.id = None
return self
示例5: undo
def undo(self):
try:
self.session.delete(self.database_entry)
except InvalidRequestError:
# database entry cannot be removed because the last call was not
# followed by a commit -> use make_transient to revert putting the
# entry into the pending state
make_transient(self.database_entry)
示例6: copy_project_sample_annotations
def copy_project_sample_annotations(cls, psa):
locus_annotations = map(SampleLocusAnnotation.copy_sample_locus_annotation, psa.locus_annotations)
db.session.expunge(psa)
make_transient(psa)
psa.id = None
psa.locus_annotations = locus_annotations
return psa
示例7: get_copy
def get_copy(cls, id):
inst = cls.get(id)
if not inst:
return inst
DBSession.expunge(inst)
make_transient(inst)
inst.id = None
return inst
示例8: new_version
def new_version(self, session):
# make us transient (removes persistent
# identity).
make_transient(self)
# set 'id' to None.
# a new PK will be generated on INSERT.
self.id = None
示例9: clone_row
def clone_row(row, event_id=None):
db.session.expunge(row)
make_transient(row)
row.id = None
if event_id:
row.event_id = event_id
save_to_db(row)
db.session.flush()
return row
示例10: transient_copy
def transient_copy(session, inst):
"""Copy a sample, this approach forces a bunch of flushes"""
from sqlalchemy.orm import make_transient
session.expunge(inst)
make_transient(inst)
inst.id = None
session.add(inst)
session.flush()
return inst
示例11: __call__
def __call__(self):
try:
self.session.add(self.database_entry)
except InvalidRequestError:
# database entry cannot be added because it was removed from the
# database -> use make_transient to send this object back to
# the transient state
make_transient(self.database_entry)
self.session.add(self.database_entry)
示例12: copy_locus_bin_set
def copy_locus_bin_set(cls, lbs):
bins = list(map(Bin.copy_bin, lbs.bins))
db.session.expunge(lbs)
make_transient(lbs)
lbs.id = None
lbs.bins = bins
return lbs
示例13: clone
def clone(model):
"""
Clones the given model and removes it's primary key
:param model:
:return:
"""
db.session.expunge(model)
make_transient(model)
model.id = None
return model
示例14: copy_artifact_estimator
def copy_artifact_estimator(cls, ae):
assert isinstance(ae, cls)
art_eqs = list(map(ArtifactEquation.copy_artifact_equation, ae.artifact_equations))
db.session.expunge(ae)
make_transient(ae)
ae.id = None
ae.artifact_equations = art_eqs
return ae
示例15: test_calculate_amount
def test_calculate_amount(self):
account = Tag(user=self.users[0], name="account")
account_group = TagGroup(user=self.users[0], tags=[account])
db.add(Transaction(user=self.users[0], amount=500, incomeTagGroup=account_group))
db.add(Transaction(user=self.users[0], amount=-100, incomeTagGroup=account_group))
db.flush()
t = Transaction(user=self.users[0], amount=33, incomeTagGroup=account_group)
make_transient(t)
t.calculate_amount()
self.assertEquals(t.amount, 33-400)