WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Unreleased
==========
- Modernize project definition to latest Python best practices. Thanks, @surister.
- Exceptions: Exceptions from the BLOB API now include their full names.
- Changed connection behaviour to fail early if the database cluster does not respond

2025/01/30 2.0.0
================
Expand Down
8 changes: 2 additions & 6 deletions docs/by-example/client.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,8 @@ respond, the request is automatically routed to the next server:
>>> connection = client.connect([invalid_host, crate_host])
>>> connection.close()

If no ``servers`` are given, the default one ``http://127.0.0.1:4200`` is used:

>>> connection = client.connect()
>>> connection.client._active_servers
['http://127.0.0.1:4200']
>>> connection.close()
If no ``servers`` are supplied to the ``connect`` method, the default address
``http://127.0.0.1:4200`` is used.
Comment on lines -32 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no server at http://127.0.0.1:4200. This test case just didn't fail because connect() did not raise an exception up until now.

Now, there is no longer a way to validate connecting to the default address per doctest file, because there is no server listening at http://127.0.0.1:4200. Because the core information is still viable, all what's left is pure prose, rephrased a bit.


If the option ``error_trace`` is set to ``True``, the client will print a whole
traceback if a server error occurs:
Expand Down
11 changes: 10 additions & 1 deletion src/crate/client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
# However, if you have executed another commercial license agreement
# with Crate these terms will supersede the license and you may use the
# software solely pursuant to the terms of the relevant commercial agreement.
import json

from verlib2 import Version
from verlib2.packaging.version import InvalidVersion

from .blob import BlobContainer
from .cursor import Cursor
Expand Down Expand Up @@ -197,14 +199,21 @@ def get_blob_container(self, container_name):

def _lowest_server_version(self):
lowest = None
server_count = len(self.client.active_servers)
connection_errors = []
for server in self.client.active_servers:
try:
_, _, version = self.client.server_infos(server)
version = Version(version)
except (ValueError, ConnectionError):
except ConnectionError as ex:
connection_errors.append(ex)
continue
except (ValueError, InvalidVersion):
continue
if not lowest or version < lowest:
lowest = version
if connection_errors and len(connection_errors) == server_count:
raise ConnectionError(json.dumps(list(map(str, connection_errors))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just raise ConnectionError(error_list)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've elaborated about it here, but I am also not sure, that's why I am also asking about your opinion.

return lowest or Version("0.0.0")

def __repr__(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/client/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from urllib3 import Timeout

import crate.client.exceptions
from crate.client import connect
from crate.client.connection import Connection
from crate.client.exceptions import ProgrammingError
Expand All @@ -12,6 +13,13 @@
from .settings import crate_host


def test_invalid_server_address():
client = Client(servers="localhost:4202")
with pytest.raises(crate.client.exceptions.ConnectionError) as excinfo:
connect(client=client)
assert excinfo.match("Server not available")


def test_lowest_server_version():
"""
Verify the lowest server version is correctly set.
Expand Down
Loading