32 ETypeNotSupportedBySources, RTypeNotSupportedBySources, |
32 ETypeNotSupportedBySources, RTypeNotSupportedBySources, |
33 BadConnectionId, Unauthorized, ValidationError, |
33 BadConnectionId, Unauthorized, ValidationError, |
34 ExecutionError, typed_eid, |
34 ExecutionError, typed_eid, |
35 CW_MIGRATION_MAP) |
35 CW_MIGRATION_MAP) |
36 from cubicweb.cwvreg import CubicWebRegistry |
36 from cubicweb.cwvreg import CubicWebRegistry |
37 from cubicweb.schema import CubicWebSchema |
37 from cubicweb.schema import VIRTUAL_RTYPES, CubicWebSchema |
38 |
38 from cubicweb import server |
39 from cubicweb.server.utils import RepoThread, LoopTask |
39 from cubicweb.server.utils import RepoThread, LoopTask |
40 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation |
40 from cubicweb.server.pool import ConnectionsPool, LateOperation, SingleLastOperation |
41 from cubicweb.server.session import Session, InternalSession |
41 from cubicweb.server.session import Session, InternalSession |
42 from cubicweb.server.querier import QuerierHelper |
42 from cubicweb.server.querier import QuerierHelper |
43 from cubicweb.server.sources import get_source |
43 from cubicweb.server.sources import get_source |
113 # relation even with '1?' cardinality if thoses relations are added in the |
113 # relation even with '1?' cardinality if thoses relations are added in the |
114 # same transaction where the entity is being created. This never occurs from |
114 # same transaction where the entity is being created. This never occurs from |
115 # the web interface but may occurs during test or dbapi connection (though |
115 # the web interface but may occurs during test or dbapi connection (though |
116 # not expected for this). So: don't do it, we pretend to ensure repository |
116 # not expected for this). So: don't do it, we pretend to ensure repository |
117 # consistency. |
117 # consistency. |
118 # XXX should probably not use unsafe_execute! |
|
119 if card[0] in '1?': |
118 if card[0] in '1?': |
120 rschema = session.repo.schema.rschema(rtype) |
119 rschema = session.repo.schema.rschema(rtype) |
121 if not rschema.inlined: |
120 if not rschema.inlined: |
122 session.unsafe_execute( |
121 session.unsafe_execute( |
123 'DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype, |
122 'DELETE X %s Y WHERE X eid %%(x)s, NOT Y eid %%(y)s' % rtype, |
933 """ |
932 """ |
934 rql = [] |
933 rql = [] |
935 eschema = self.schema.eschema(etype) |
934 eschema = self.schema.eschema(etype) |
936 for rschema, targetschemas, x in eschema.relation_definitions(): |
935 for rschema, targetschemas, x in eschema.relation_definitions(): |
937 rtype = rschema.type |
936 rtype = rschema.type |
938 if rtype == 'identity': |
937 if rtype in VIRTUAL_RTYPES: |
939 continue |
938 continue |
940 var = '%s%s' % (rtype.upper(), x.upper()) |
939 var = '%s%s' % (rtype.upper(), x.upper()) |
941 if x == 'subject': |
940 if x == 'subject': |
942 # don't skip inlined relation so they are regularly |
941 # don't skip inlined relation so they are regularly |
943 # deleted and so hooks are correctly called |
942 # deleted and so hooks are correctly called |