~ubuntu-branches/debian/sid/sqlalchemy/sid

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/orm/attributes.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2014-06-27 20:17:13 UTC
  • mfrom: (1.4.28)
  • Revision ID: package-import@ubuntu.com-20140627201713-g6p1kq8q1qenztrv
Tags: 0.9.6-1
* New upstream release
* Remove Python 3.X build tag files, thanks to Matthias Urlichs for the
  patch (closes: #747852)
* python-fdb isn't in the Debian archive yet so default dialect for firebird://
  URLs is changed to obsolete kinterbasdb, thanks to Russell Stuart for the
  patch (closes: #752145)

Show diffs side-by-side

added added

removed removed

Lines of Context:
98
98
          any other kind of SQL expression other than a :class:`.Column`,
99
99
          the attribute will refer to the :attr:`.MapperProperty.info` dictionary
100
100
          associated directly with the :class:`.ColumnProperty`, assuming the SQL
101
 
          expression itself does not have it's own ``.info`` attribute
 
101
          expression itself does not have its own ``.info`` attribute
102
102
          (which should be the case, unless a user-defined SQL construct
103
103
          has defined one).
104
104
 
532
532
    def get_history(self, state, dict_, passive=PASSIVE_OFF):
533
533
        raise NotImplementedError()
534
534
 
535
 
    def get_all_pending(self, state, dict_):
 
535
    def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
536
536
        """Return a list of tuples of (state, obj)
537
537
        for all objects in this attribute's current state
538
538
        + history.
568
568
            # if history present, don't load
569
569
            key = self.key
570
570
            if key not in state.committed_state or \
571
 
                state.committed_state[key] is NEVER_SET:
 
571
                    state.committed_state[key] is NEVER_SET:
572
572
                if not passive & CALLABLES_OK:
573
573
                    return PASSIVE_NO_RESULT
574
574
 
737
737
            else:
738
738
                return History.from_object_attribute(self, state, current)
739
739
 
740
 
    def get_all_pending(self, state, dict_):
 
740
    def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
741
741
        if self.key in dict_:
742
742
            current = dict_[self.key]
743
 
            if current is not None:
744
 
                ret = [(instance_state(current), current)]
745
 
            else:
746
 
                ret = [(None, None)]
747
 
 
748
 
            if self.key in state.committed_state:
749
 
                original = state.committed_state[self.key]
750
 
                if original not in (NEVER_SET, PASSIVE_NO_RESULT, None) and \
 
743
        elif passive & CALLABLES_OK:
 
744
            current = self.get(state, dict_, passive=passive)
 
745
        else:
 
746
            return []
 
747
 
 
748
        # can't use __hash__(), can't use __eq__() here
 
749
        if current is not None and \
 
750
                current is not PASSIVE_NO_RESULT and \
 
751
                current is not NEVER_SET:
 
752
            ret = [(instance_state(current), current)]
 
753
        else:
 
754
            ret = [(None, None)]
 
755
 
 
756
        if self.key in state.committed_state:
 
757
            original = state.committed_state[self.key]
 
758
            if original is not None and \
 
759
                    original is not PASSIVE_NO_RESULT and \
 
760
                    original is not NEVER_SET and \
751
761
                    original is not current:
752
762
 
753
 
                    ret.append((instance_state(original), original))
754
 
            return ret
755
 
        else:
756
 
            return []
 
763
                ret.append((instance_state(original), original))
 
764
        return ret
757
765
 
758
766
    def set(self, state, dict_, value, initiator,
759
767
                passive=PASSIVE_OFF, check_old=None, pop=False):
763
771
        if self.dispatch._active_history:
764
772
            old = self.get(state, dict_, passive=PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH)
765
773
        else:
 
774
            # would like to call with PASSIVE_NO_FETCH ^ INIT_OK.  However,
 
775
            # we have a long-standing behavior that a "get()" on never set
 
776
            # should implicitly set the value to None.  Leaving INIT_OK
 
777
            # set here means we are consistent whether or not we did a get
 
778
            # first.
 
779
            # see test_use_object_set_None vs. test_use_object_get_first_set_None
 
780
            # in test_attributes.py
766
781
            old = self.get(state, dict_, passive=PASSIVE_NO_FETCH)
767
782
 
768
783
        if check_old is not None and \
777
792
                   state_str(state),
778
793
                   self.key
779
794
                ))
 
795
 
780
796
        value = self.fire_replace_event(state, dict_, value, old, initiator)
781
797
        dict_[self.key] = value
782
798
 
793
809
    def fire_replace_event(self, state, dict_, value, previous, initiator):
794
810
        if self.trackparent:
795
811
            if (previous is not value and
796
 
                previous is not None and
797
 
                previous is not PASSIVE_NO_RESULT):
 
812
                    previous not in (None, PASSIVE_NO_RESULT, NEVER_SET)):
798
813
                self.sethasparent(instance_state(previous), state, False)
799
814
 
800
815
        for fn in self.dispatch.set:
852
867
        else:
853
868
            return History.from_collection(self, state, current)
854
869
 
855
 
    def get_all_pending(self, state, dict_):
 
870
    def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
 
871
        # NOTE: passive is ignored here at the moment
 
872
 
856
873
        if self.key not in dict_:
857
874
            return []
858
875
 
1080
1097
    def emit_backref_from_scalar_set_event(state, child, oldchild, initiator):
1081
1098
        if oldchild is child:
1082
1099
            return child
1083
 
        if oldchild is not None and oldchild is not PASSIVE_NO_RESULT:
 
1100
        if oldchild is not None and \
 
1101
                oldchild is not PASSIVE_NO_RESULT and \
 
1102
                oldchild is not NEVER_SET:
1084
1103
            # With lazy=None, there's no guarantee that the full collection is
1085
1104
            # present when updating via a backref.
1086
1105
            old_state, old_dict = instance_state(oldchild),\
1208
1227
 
1209
1228
        return not bool(
1210
1229
                        (self.added or self.deleted)
1211
 
                        or self.unchanged and self.unchanged != [None]
 
1230
                        or self.unchanged
1212
1231
                    )
1213
1232
 
1214
1233
    def sum(self):