Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileStorage: Discrepancy between iterator() and record_iternext() on empty storages (record_iternext underspecified) #330

Open
jamadden opened this issue Oct 9, 2020 · 0 comments

Comments

@jamadden
Copy link
Member

jamadden commented Oct 9, 2020

In ZODB 5.6 (and almost certainly previous versions), or any version of Python, FileStorage.iterator gracefully handles an empty storage, while record_iternext raises an exception.

>>> from ZODB import config
>>> conf_str = """
... <filestorage>
...    path /tmp/Data.fs
... </filestorage>
... """
>>> storage = config.storageFromString(conf_str)
>>> list(storage.iterator())
[]
>>> storage.record_iternext(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/ZODB/src/ZODB/FileStorage/FileStorage.py", line 1409, in record_iternext
    oid = index.minKey(next)
  File "//ZODB/src/ZODB/fsIndex.py", line 236, in minKey
    smallest_prefix = self._data.minKey()
ValueError: empty tree

This is a problem because record_iternext doesn't specify any behaviour around empty storages; it doesn't mention exceptions. I would expect record_iternext to behave like iterator and return a slate of None values, or specify what exception to watch for in that specific case (StopIteration?).

The existing documentation and example, and the iteration-cookie design of record_iternext, suggest that returning a bunch of Nones is likely to break existing clients just as badly as a new exception, so perhaps just specifying the ValueError is the most practical approach.

This comes up in the context of RelStorage and copyTransactionsFrom: For history-free RelStorage instances, it's substantially faster to implement copyTransactionsFrom using record_iternext than iterator().

jamadden added a commit to zodb/relstorage that referenced this issue Oct 9, 2020
Add tests with blobs, more incremental testing, and tests with history-free destinations.

This found, and added a workaround for, zopefoundation/ZODB#330
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant