diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-11-22 14:28:21 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-11-22 14:35:31 -0500 |
| commit | 26ba917996ec67ca24afa8c853f634edc08b06bb (patch) | |
| tree | 5877a86f475b437090bf79c37ed18dae382a7f37 /lib/sqlalchemy | |
| parent | b1f8c642301a96c084e4dec44db108db927a69d9 (diff) | |
| download | sqlalchemy-26ba917996ec67ca24afa8c853f634edc08b06bb.tar.gz | |
Raise for persistence casades set with viewonly=True
An error is raised if any persistence-related "cascade" settings are made
on a :func:`.relationship` that also sets up viewonly=True. The "cascade"
settings now default to non-persistence related settings only when viewonly
is also set. This is the continuation from :ticket:`4993` where this
setting was changed to emit a warning in 1.3.
Fixes: #4994
Change-Id: Ic70ff4d9980e422ade474c5a0ad49756c6b8a048
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/relationships.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/lib/sqlalchemy/orm/relationships.py b/lib/sqlalchemy/orm/relationships.py index 9a382b7cd..fc3e78ea1 100644 --- a/lib/sqlalchemy/orm/relationships.py +++ b/lib/sqlalchemy/orm/relationships.py @@ -901,8 +901,10 @@ class RelationshipProperty(StrategizedProperty): if cascade is not False: self.cascade = cascade + elif self.viewonly: + self.cascade = "none" else: - self._set_cascade("save-update, merge", warn=False) + self.cascade = "save-update, merge" self.order_by = order_by @@ -2029,28 +2031,18 @@ class RelationshipProperty(StrategizedProperty): def cascade(self, cascade): self._set_cascade(cascade) - def _set_cascade(self, cascade, warn=True): + def _set_cascade(self, cascade): cascade = CascadeOptions(cascade) - if warn and self.viewonly: + if self.viewonly: non_viewonly = set(cascade).difference( CascadeOptions._viewonly_cascades ) if non_viewonly: - # we are warning here rather than warn deprecated as this - # setting actively does the wrong thing and Python shows - # regular warnings more aggressively than deprecation warnings - # by default. There's no other guard against setting active - # persistence cascades under viewonly=True so this will raise - # in 1.4. - util.warn( - 'Cascade settings "%s" should not be combined with a ' - "viewonly=True relationship. This configuration will " - "raise an error in version 1.4. Note that in versions " - "prior to 1.4, " - "these cascade settings may still produce a mutating " - "effect even though this relationship is marked as " - "viewonly=True." % (", ".join(sorted(non_viewonly))) + raise sa_exc.ArgumentError( + 'Cascade settings "%s" apply to persistence operations ' + "and should not be combined with a viewonly=True " + "relationship." % (", ".join(sorted(non_viewonly))) ) if "mapper" in self.__dict__: |
