Skip to content

Remove Bookmark in favor or Bookmarks #1175

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

Merged
merged 2 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ See also https://github.com/neo4j/neo4j-python-driver/wiki for a full changelog.
is already active.
- Remove deprecated `Record.__getslice__`. This magic method has been removed in Python 3.0.
If you were calling it directly, please use `Record.__getitem__(slice(...))` or simply `record[...]` instead.
- Remove deprecated class `neo4j.Bookmark` in favor of `neo4j.Bookmarks`.
- Remove deprecated class `session.last_bookmark()` in favor of `last_bookmarks()`.


## Version 5.28
Expand Down
10 changes: 5 additions & 5 deletions docs/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,6 @@ Session

.. automethod:: last_bookmarks

.. automethod:: last_bookmark

.. automethod:: begin_transaction

.. automethod:: read_transaction
Expand Down Expand Up @@ -984,13 +982,18 @@ Optional :class:`neo4j.Bookmarks`. Use this to causally chain sessions.
See :meth:`.Session.last_bookmarks` or :meth:`.AsyncSession.last_bookmarks` for
more information.

:Type: ``None``, ``neo4j.Bookmarks``

:Default: :data:`None`

.. deprecated:: 5.0
Alternatively, an iterable of strings can be passed. This usage is
deprecated and will be removed in a future release. Please use a
:class:`neo4j.Bookmarks` object instead.

.. versionchanged:: 6.0
Only accepts :class:`neo4j.Bookmarks` objects or :data:`None`.


.. _database-ref:

Expand Down Expand Up @@ -1940,9 +1943,6 @@ Bookmarks
:members:
:special-members: __bool__, __add__, __iter__

.. autoclass:: neo4j.Bookmark
:members:


BookmarkManager
===============
Expand Down
2 changes: 0 additions & 2 deletions docs/source/async_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ AsyncSession

.. automethod:: last_bookmarks

.. automethod:: last_bookmark

.. automethod:: begin_transaction

.. automethod:: read_transaction
Expand Down
2 changes: 0 additions & 2 deletions src/neo4j/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
AuthToken,
basic_auth,
bearer_auth,
Bookmark,
Bookmarks,
custom_auth,
DEFAULT_DATABASE,
Expand Down Expand Up @@ -126,7 +125,6 @@
"Auth",
"AuthToken",
"BoltDriver",
"Bookmark",
"Bookmarks",
"Driver",
"EagerResult",
Expand Down
35 changes: 0 additions & 35 deletions src/neo4j/_async/work/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,41 +339,6 @@ async def run(

return self._auto_result

@deprecated(
"`last_bookmark` has been deprecated in favor of `last_bookmarks`. "
"This method can lead to unexpected behaviour."
)
@AsyncNonConcurrentMethodChecker._non_concurrent_method
async def last_bookmark(self) -> str | None:
"""
Get the bookmark received following the last completed transaction.

Note: For auto-commit transactions (:meth:`Session.run`), this will
trigger :meth:`Result.consume` for the current result.

.. warning::
This method can lead to unexpected behaviour if the session has not
yet successfully completed a transaction.

:returns: last bookmark

.. deprecated:: 5.0
:meth:`last_bookmark` will be removed in version 6.0.
Use :meth:`last_bookmarks` instead.
"""
# The set of bookmarks to be passed into the next transaction.

if self._auto_result:
await self._auto_result.consume()

if self._transaction and self._transaction._closed():
await self._update_bookmark(self._transaction._bookmark)
self._transaction = None

if self._bookmarks:
return self._bookmarks[-1]
return None

@AsyncNonConcurrentMethodChecker._non_concurrent_method
async def last_bookmarks(self) -> Bookmarks:
"""
Expand Down
16 changes: 4 additions & 12 deletions src/neo4j/_async/work/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,13 @@ def _set_pinned_database(self, database):
self._config.database = database

def _initialize_bookmarks(self, bookmarks):
if isinstance(bookmarks, Bookmarks):
prepared_bookmarks = tuple(bookmarks.raw_values)
elif hasattr(bookmarks, "__iter__"):
deprecation_warn(
"Passing an iterable as `bookmarks` to `Session` is "
"deprecated. Please use a `Bookmarks` instance.",
stack_level=5,
)
prepared_bookmarks = tuple(bookmarks)
elif not bookmarks:
if bookmarks is None:
prepared_bookmarks = ()
elif isinstance(bookmarks, Bookmarks):
prepared_bookmarks = tuple(bookmarks.raw_values)
else:
raise TypeError(
"Bookmarks must be an instance of Bookmarks or an "
"iterable of raw bookmarks (deprecated)."
"Bookmarks must be an instance of Bookmarks or None."
)
self._initial_bookmarks = self._bookmarks = prepared_bookmarks

Expand Down
35 changes: 0 additions & 35 deletions src/neo4j/_sync/work/session.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions src/neo4j/_sync/work/workspace.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 0 additions & 46 deletions src/neo4j/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"AsyncBookmarkManager",
"Auth",
"AuthToken",
"Bookmark",
"BookmarkManager",
"Bookmarks",
"ServerInfo",
Expand Down Expand Up @@ -234,51 +233,6 @@ def custom_auth(
return Auth(scheme, principal, credentials, realm, **parameters)


# TODO: 6.0 - remove this class
@deprecated("Use the `Bookmarks` class instead.")
class Bookmark:
"""
A Bookmark object contains an immutable list of bookmark string values.

:param values: ASCII string values

.. deprecated:: 5.0
`Bookmark` will be removed in version 6.0.
Use :class:`Bookmarks` instead.
"""

def __init__(self, *values: str) -> None:
if values:
bookmarks = []
for ix in values:
try:
if ix:
ix.encode("ascii")
bookmarks.append(ix)
except UnicodeEncodeError as e:
raise ValueError(f"The value {ix} is not ASCII") from e
self._values = frozenset(bookmarks)
else:
self._values = frozenset()

def __repr__(self) -> str:
"""
Represent the container as str.

:returns: repr string with sorted values
"""
values = ", ".join([f"'{ix}'" for ix in sorted(self._values)])
return f"<Bookmark values={{{values}}}>"

def __bool__(self) -> bool:
return bool(self._values)

@property
def values(self) -> frozenset:
""":returns: immutable list of bookmark string values"""
return self._values


class Bookmarks:
"""
Container for an immutable set of bookmark string values.
Expand Down
37 changes: 0 additions & 37 deletions tests/unit/async_/work/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,43 +220,6 @@ async def test_session_returns_bookmarks_directly(
assert ret_bookmarks == frozenset(bookmark_values)


@pytest.mark.parametrize(
"bookmarks", (None, [], ["abc"], ["foo", "bar"], ("1", "two"))
)
@mark_async_test
async def test_session_last_bookmark_is_deprecated(async_fake_pool, bookmarks):
if bookmarks is not None:
with pytest.warns(DeprecationWarning):
session = AsyncSession(
async_fake_pool, SessionConfig(bookmarks=bookmarks)
)
else:
session = AsyncSession(
async_fake_pool, SessionConfig(bookmarks=bookmarks)
)
async with session:
with pytest.warns(DeprecationWarning):
if bookmarks:
assert (await session.last_bookmark()) == bookmarks[-1]
else:
assert (await session.last_bookmark()) is None


@pytest.mark.parametrize(
"bookmarks", (("foo",), ("foo", "bar"), (), ["foo", "bar"], {"a", "b"})
)
@mark_async_test
async def test_session_bookmarks_as_iterable_is_deprecated(
async_fake_pool, bookmarks
):
with pytest.warns(DeprecationWarning):
async with AsyncSession(
async_fake_pool, SessionConfig(bookmarks=bookmarks)
) as session:
ret_bookmarks = (await session.last_bookmarks()).raw_values
assert ret_bookmarks == frozenset(bookmarks)


@pytest.mark.parametrize(
("query", "error_type"),
(
Expand Down
Loading