--- a/entities/wfobjs.py Wed Oct 14 14:09:22 2009 +0200
+++ b/entities/wfobjs.py Wed Oct 14 14:09:40 2009 +0200
@@ -415,18 +415,11 @@
@cached
def cwetype_workflow(self):
"""return the default workflow for entities of this type"""
- # XXX CWEType method
- wfrset = self.req.execute('Any WF WHERE X is ET, X eid %(x)s, '
- 'WF workflow_of ET', {'x': self.eid}, 'x')
- if len(wfrset) == 1:
+ wfrset = self.req.execute('Any WF WHERE ET default_workflow WF, '
+ 'ET name %(et)s', {'et': self.id})
+ if wfrset:
return wfrset.get_entity(0, 0)
- if len(wfrset) > 1:
- for wf in wfrset.entities():
- if wf.is_default_workflow_of(self.id):
- return wf
- self.warning("can't find default workflow for %s", self.id)
- else:
- self.warning("can't find any workflow for %s", self.id)
+ self.warning("can't find any workflow for %s", self.id)
return None
def possible_transitions(self, type='normal'):
--- a/entity.py Wed Oct 14 14:09:22 2009 +0200
+++ b/entity.py Wed Oct 14 14:09:40 2009 +0200
@@ -18,7 +18,7 @@
from rql import parse
from rql.utils import rqlvar_maker
-from cubicweb import Unauthorized
+from cubicweb import Unauthorized, typed_eid
from cubicweb.rset import ResultSet
from cubicweb.selectors import yes
from cubicweb.appobject import AppObject
@@ -338,7 +338,7 @@
meaning that the entity has to be created
"""
try:
- int(self.eid)
+ typed_eid(self.eid)
return True
except (ValueError, TypeError):
return False
@@ -845,9 +845,14 @@
self._related_cache.pop('%s_%s' % (rtype, role), None)
def clear_all_caches(self):
+ haseid = 'eid' in self
self.clear()
for rschema, _, role in self.e_schema.relation_definitions():
self.clear_related_cache(rschema.type, role)
+ # set eid if it was in, else we may get nasty error while editing this
+ # entity if it's bound to a repo session
+ if haseid:
+ self['eid'] = self.eid
# raw edition utilities ###################################################
--- a/misc/migration/3.5.3_Any.py Wed Oct 14 14:09:22 2009 +0200
+++ b/misc/migration/3.5.3_Any.py Wed Oct 14 14:09:40 2009 +0200
@@ -1,7 +1,7 @@
# type attribute might already be there if migrating from
# version < 3.5 to version >= 3.5.3, BaseTransition being added
# in bootstrap_migration
-if versions_map['cubicweb'][0] < (3, 5, 0):
+if versions_map['cubicweb'][0] >= (3, 5, 0):
add_attribute('BaseTransition', 'type')
sync_schema_props_perms('state_of')
sync_schema_props_perms('transition_of')
--- a/server/hooks.py Wed Oct 14 14:09:22 2009 +0200
+++ b/server/hooks.py Wed Oct 14 14:09:40 2009 +0200
@@ -553,13 +553,20 @@
assert forentity.current_state.eid == entity['to_state'], (
forentity.eid, forentity.current_state.name)
if forentity.main_workflow.eid != forentity.current_workflow.eid:
+ SubWorkflowExitOp(session, forentity=forentity, trinfo=entity)
+
+class SubWorkflowExitOp(PreCommitOperation):
+ def precommit_event(self):
+ session = self.session
+ forentity = self.forentity
+ trinfo = self.trinfo
# we're in a subworkflow, check if we've reached an exit point
wftr = forentity.subworkflow_input_transition()
if wftr is None:
# inconsistency detected
- msg = entity.req._("state doesn't belong to entity's current workflow")
- raise ValidationError(entity.eid, {'to_state': msg})
- tostate = wftr.get_exit_point(forentity, entity['to_state'])
+ msg = session._("state doesn't belong to entity's current workflow")
+ raise ValidationError(self.trinfo.eid, {'to_state': msg})
+ tostate = wftr.get_exit_point(forentity, trinfo['to_state'])
if tostate is not None:
# reached an exit point
msg = session._('exiting from subworkflow %s')