Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix: raise if trying to change ordering_mode after session has started #1252

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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 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
7 changes: 5 additions & 2 deletions 7 bigframes/_config/bigquery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,11 @@ def ordering_mode(self) -> Literal["strict", "partial"]:
return self._ordering_mode.value

@ordering_mode.setter
def ordering_mode(self, ordering_mode: Literal["strict", "partial"]) -> None:
self._ordering_mode = _validate_ordering_mode(ordering_mode)
def ordering_mode(self, value: Literal["strict", "partial"]) -> None:
ordering_mode = _validate_ordering_mode(value)
if self._session_started and self._ordering_mode != ordering_mode:
raise ValueError(SESSION_STARTED_MESSAGE.format(attribute="ordering_mode"))
self._ordering_mode = ordering_mode

@property
def client_endpoints_override(self) -> dict:
Expand Down
51 changes: 34 additions & 17 deletions 51 tests/unit/_config/test_bigquery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
# limitations under the License.

import re
from unittest import mock
import warnings

import google.auth.credentials
import pytest

import bigframes
Expand All @@ -35,6 +37,7 @@
("kms_key_name", "kms/key/name/1", "kms/key/name/2"),
("skip_bq_connection_check", False, True),
("client_endpoints_override", {}, {"bqclient": "endpoint_address"}),
("ordering_mode", "strict", "partial"),
],
)
def test_setter_raises_if_session_started(attribute, original_value, new_value):
Expand All @@ -57,32 +60,46 @@ def test_setter_raises_if_session_started(attribute, original_value, new_value):
@pytest.mark.parametrize(
[
"attribute",
"original_value",
],
[
(attribute,)
for attribute in [
"application_name",
"credentials",
"location",
"project",
"bq_connection",
"use_regional_endpoints",
"bq_kms_key_name",
"client_endpoints_override",
]
("application_name", "test-partner"),
("location", "us-east1"),
("project", "my-project"),
("bq_connection", "path/to/connection/1"),
("use_regional_endpoints", True),
("kms_key_name", "kms/key/name/1"),
("skip_bq_connection_check", True),
("client_endpoints_override", {"bqclient": "endpoint_address"}),
("ordering_mode", "partial"),
],
)
def test_setter_if_session_started_but_setting_the_same_value(attribute):
def test_setter_if_session_started_but_setting_the_same_value(
attribute, original_value
):
options = bigquery_options.BigQueryOptions()
original_object = object()
setattr(options, attribute, original_object)
assert getattr(options, attribute) is original_object
setattr(options, attribute, original_value)
assert getattr(options, attribute) == original_value

# This should work fine since we're setting the same value as before.
options._session_started = True
setattr(options, attribute, original_object)
setattr(options, attribute, original_value)

assert getattr(options, attribute) == original_value

assert getattr(options, attribute) is original_object

def test_setter_if_session_started_but_setting_the_same_credentials_object():
options = bigquery_options.BigQueryOptions()
original_object = mock.create_autospec(
google.auth.credentials.Credentials, instance=True
)
options.credentials = original_object
assert options.credentials is original_object

# This should work fine since we're setting the same value as before.
options._session_started = True
options.credentials = original_object
assert options.credentials is original_object


@pytest.mark.parametrize(
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.