classification
Title: Deprecate nonstandard behavior of a dumbdbm database
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Claudiu.Popa, python-dev, r.david.murray, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-06-10 18:31 by serhiy.storchaka, last changed 2016-07-17 08:38 by serhiy.storchaka. This issue is now closed.

Files
File name Uploaded Description Edit
dbm_dumb_deprecations.patch serhiy.storchaka, 2014-06-10 18:31 review
dbm_dumb_deprecations2.patch serhiy.storchaka, 2016-06-19 22:06 review
Messages (9)
msg220185 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-06-10 18:31
Unlike to other dbm implementations, a dumpdbm database is always opened for update, and will be created if it does not exist.  We can fix this discrepancy and implement common behavior for 'r' and 'w' modes, but this will change current behavior and some deprecation period is needed.

Here is a patch (based on patch by Claudiu Popa, submitted in issue18039), which adds deprecation warnings for cases when current behavior differs from desired: invalid values for the flag parameter (will raise ValueError in future), opening non-existing database in 'r' or 'w' mode (will raise dbm.dumb.error), modifying a database opened for reading only (will raise dbm.dumb.error).

This patch needs approving by other core developer.
msg221212 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-06-22 01:35
The core idea is reasonable.  

The patch overreaches by adding readonly warnings to __setitem__ and __delitem__ which will spew-out on every call (these could be ignored or set to warn once by the user but that is PITA).

Minor nit.  We have a little PEP-8 overkill on the string splits:

+            with self.assertWarnsRegex(DeprecationWarning,
+                                       "The database file is missing, the "
+                                       "semantics of the 'c' flag will "
+                                       "be used."):
msg221448 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-06-24 10:16
Thanks Raymond for your attention.

Readonly warnings are emitted only when dumpdbm database opened in read only mode. They will be turned into exceptions in future (3.6 or 3.7). Annoying warnings on changed in future operations is desirable effect.

If you worry about performance hit of such checks, __setitem__ and __delitem__ are expensive operations doing file I/O.
msg221490 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-06-24 20:10
I'm not worries about the performance.  I think the warnings and checks don't need to be there are all (API creep).  AFAICT, this has never been requested or needed in the entire history of the dumbdbm.

Your original goal of changing the default update mode is worthwhile.
msg221500 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-06-24 21:03
The point is to make the API consistent.  So if the other dbm modules raise an error when __setitem__/__delitem__ are called on an R/O db, then the warnings are appropriate (but should mention that this will be an error in the future).

The warnings will only be printed once per run of python, unless I'm completely misremembering how deprecation warnings work.
msg221521 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-06-25 04:12
Feel free to ignore my advice and make unnecessary changes to a very old, stable API.
msg242965 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-05-12 11:47
Warnings are not raised by default. They are raised only when the database is opened with the 'r' mode and then modified.

The earlier we start deprecation period, the earlier we could add true "read-only" and "update existing" modes to dbm.dumb.
msg268874 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-19 22:06
Patch updated. Added What's New entry.

We already lost 2 years and the 3.5 release. I don't want to lost 3.6 too.
msg269873 - (view) Author: Roundup Robot (python-dev) Date: 2016-07-06 09:22
New changeset 62da75b29b29 by Serhiy Storchaka in branch 'default':
Issue #21708: Deprecated dbm.dumb behavior that differs from common dbm
https://hg.python.org/cpython/rev/62da75b29b29
History
Date User Action Args
2016-07-17 08:38:20serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-07-06 09:22:17python-devsetnosy: + python-dev
messages: + msg269873
2016-06-19 22:06:08serhiy.storchakasetfiles: + dbm_dumb_deprecations2.patch
versions: + Python 3.6, - Python 3.5
messages: + msg268874

assignee: serhiy.storchaka
components: + Library (Lib)
2015-05-12 11:47:44serhiy.storchakasetmessages: + msg242965
2014-06-25 04:12:41rhettingersetassignee: rhettinger -> (no value)
messages: + msg221521
2014-06-24 21:03:41r.david.murraysetmessages: + msg221500
2014-06-24 20:10:42rhettingersetmessages: + msg221490
2014-06-24 10:16:48serhiy.storchakasetmessages: + msg221448
2014-06-22 01:35:29rhettingersetmessages: + msg221212
2014-06-21 03:16:51rhettingersetassignee: serhiy.storchaka -> rhettinger

nosy: + rhettinger
2014-06-10 18:31:22serhiy.storchakacreate