Skip to content

Commit a57bda4

Browse files
committed
feat: utilize all SIM rules
JIRA: TRIVIAL risk: low
1 parent d51ea62 commit a57bda4

14 files changed

Lines changed: 63 additions & 87 deletions

File tree

gooddata-dbt/gooddata_dbt/args.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ def set_gooddata_endpoint_args(parser: argparse.ArgumentParser) -> None:
3737
)
3838
# Alternative - use profile.yml file
3939
env_profiles = os.getenv("GOODDATA_PROFILES")
40-
if env_profiles:
41-
env_profiles_list = env_profiles.split(" ")
42-
else:
43-
env_profiles_list = []
40+
env_profiles_list = env_profiles.split(" ") if env_profiles else []
4441
parser.add_argument(
4542
"-gp",
4643
"--gooddata-profiles",

gooddata-flight-server/gooddata_flight_server/errors/error_code.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,15 @@ def _init_names(cls: Any) -> Any:
2929

3030

3131
_RetryFlagsLiteral: TypeAlias = Literal["any", "other", "here"]
32+
_FlagsMapping = {
33+
Literal["any"]: _RETRY_ANY_FLAG,
34+
Literal["here"]: _RETRY_HERE_FLAG,
35+
Literal["other"]: _RETRY_OTHER_FLAG,
36+
}
3237

3338

3439
def _get_flags(retry: Optional[_RetryFlagsLiteral] = None) -> int:
35-
if retry == "any":
36-
return _RETRY_ANY_FLAG
37-
elif retry == "here":
38-
return _RETRY_HERE_FLAG
39-
elif retry == "other":
40-
return _RETRY_OTHER_FLAG
41-
42-
return 0x0
40+
return _FlagsMapping.get(retry, 0x0)
4341

4442

4543
def _error_code(code: int, retry: Optional[_RetryFlagsLiteral] = None) -> int:

gooddata-flight-server/gooddata_flight_server/server/flight_rpc/flight_service.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@
2525

2626

2727
def _get_flight_server_locations(config: ServerConfig) -> tuple[str, str]:
28-
if config.use_tls:
29-
transport = "grpc+tls"
30-
else:
31-
transport = "grpc"
28+
transport = "grpc+tls" if config.use_tls else "grpc"
3229

3330
return (
3431
f"{transport}://{config.listen_host}:{config.listen_port}",

gooddata-flight-server/gooddata_flight_server/tasks/thread_task_executor.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -500,23 +500,25 @@ def _task_run_wrapper(self, task_execution: _TaskExecution) -> Any:
500500
structlog.contextvars.clear_contextvars()
501501
structlog.contextvars.bind_contextvars(**logging_ctx)
502502

503-
with task_execution.use_execution_span():
504-
with SERVER_TRACER.start_as_current_span("task_run", attributes={TaskAttributes.TaskId: task.task_id}):
505-
self._logger.info(
506-
"task_run",
507-
task_id=task.task_id,
508-
waited=stats.run_waited_duration,
509-
)
510-
self._metrics.wait_time.observe(stats.run_waited_duration)
503+
with (
504+
task_execution.use_execution_span(),
505+
SERVER_TRACER.start_as_current_span("task_run", attributes={TaskAttributes.TaskId: task.task_id}),
506+
):
507+
self._logger.info(
508+
"task_run",
509+
task_id=task.task_id,
510+
waited=stats.run_waited_duration,
511+
)
512+
self._metrics.wait_time.observe(stats.run_waited_duration)
511513

512-
try:
513-
return task.run()
514-
finally:
515-
stats.run_completed = time.perf_counter()
516-
stats.completed = stats.run_completed
514+
try:
515+
return task.run()
516+
finally:
517+
stats.run_completed = time.perf_counter()
518+
stats.completed = stats.run_completed
517519

518-
self._metrics.task_duration.observe(stats.run_duration)
519-
self._metrics.task_e2e_duration.observe(stats.duration)
520+
self._metrics.task_duration.observe(stats.run_duration)
521+
self._metrics.task_e2e_duration.observe(stats.duration)
520522

521523
def _finish_task_with_result(self, task_execution: "_TaskExecution", result: TaskExecutionResult) -> None:
522524
task = task_execution.task
@@ -534,11 +536,10 @@ def run_task(
534536
self,
535537
task_execution: _TaskExecution,
536538
) -> Future:
537-
with task_execution.use_execution_span():
538-
with SERVER_TRACER.start_as_current_span("task_run_submit"):
539-
task_execution.stats.run_submitted = time.perf_counter()
539+
with task_execution.use_execution_span(), SERVER_TRACER.start_as_current_span("task_run_submit"):
540+
task_execution.stats.run_submitted = time.perf_counter()
540541

541-
return self._executor.submit(self._task_run_wrapper, task_execution)
542+
return self._executor.submit(self._task_run_wrapper, task_execution)
542543

543544
def process_task_result(
544545
self,

gooddata-flight-server/tests/server/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _find_free_port():
3636

3737
def _clean_env_vars():
3838
to_drop = []
39-
for key in os.environ.keys():
39+
for key in os.environ:
4040
if key.startswith("GOODDATA_FLIGHT"):
4141
to_drop.append(key)
4242

gooddata-flight-server/tests/server/test_server.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ def test_smoke_with_auth_fail1(tls_ca_cert):
6060
os.environ["GOODDATA_FLIGHT_SERVER__AUTHENTICATION_METHOD"] = "token"
6161
os.environ["GOODDATA_FLIGHT_ENUMERATED_TOKENS__TOKENS"] = '["t1", "t2"]'
6262

63-
with server(_TestingMethods(), tls=True) as s:
64-
with pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
65-
list(pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert).list_flights())
63+
with server(_TestingMethods(), tls=True) as s, pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
64+
list(pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert).list_flights())
6665

6766

6867
def test_smoke_with_auth_fail2(tls_ca_cert):
@@ -71,9 +70,8 @@ def test_smoke_with_auth_fail2(tls_ca_cert):
7170

7271
# important: header names must be lowercase
7372
opts = FlightCallOptions(headers=[(b"authorization", b"Bearer 123")])
74-
with server(_TestingMethods(), tls=True) as s:
75-
with pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
76-
list(pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert).list_flights(b"", opts))
73+
with server(_TestingMethods(), tls=True) as s, pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
74+
list(pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert).list_flights(b"", opts))
7775

7876

7977
def test_smoke_with_auth1(tls_ca_cert):
@@ -107,10 +105,9 @@ def test_smoke_with_custom_auth_fail1(tls_ca_cert):
107105
os.environ["GOODDATA_FLIGHT_SERVER__TOKEN_VERIFICATION"] = "tests.server.testing_token_verifier"
108106

109107
opts = FlightCallOptions(headers=[(b"x-some-bad-header", b"test_token")])
110-
with server(_TestingMethods(), tls=True) as s:
111-
with pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
112-
c = pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert)
113-
tuple(c.list_flights(b"", opts))
108+
with server(_TestingMethods(), tls=True) as s, pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
109+
c = pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert)
110+
tuple(c.list_flights(b"", opts))
114111

115112

116113
def test_smoke_with_custom_auth_fail2(tls_ca_cert):
@@ -119,7 +116,6 @@ def test_smoke_with_custom_auth_fail2(tls_ca_cert):
119116
os.environ["GOODDATA_FLIGHT_SERVER__TOKEN_VERIFICATION"] = "tests.server.testing_token_verifier"
120117

121118
opts = FlightCallOptions(headers=[(b"x-custom-token-header", b"invalid")])
122-
with server(_TestingMethods(), tls=True) as s:
123-
with pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
124-
c = pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert)
125-
tuple(c.list_flights(b"", opts))
119+
with server(_TestingMethods(), tls=True) as s, pytest.raises(pyarrow.flight.FlightUnauthenticatedError):
120+
c = pyarrow.flight.FlightClient(s.location, tls_root_certs=tls_ca_cert)
121+
tuple(c.list_flights(b"", opts))

gooddata-pandas/gooddata_pandas/data_access.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ def _process_index(self, index_by: Optional[IndexDef] = None) -> None:
119119
if index_by is None:
120120
return
121121

122-
if not isinstance(index_by, dict):
123-
_index_by = {self._DEFAULT_INDEX_NAME: index_by}
124-
else:
125-
_index_by = index_by
122+
_index_by = {self._DEFAULT_INDEX_NAME: index_by} if not isinstance(index_by, dict) else index_by
126123

127124
for index_name, index_def in _index_by.items():
128125
if isinstance(index_def, str) and (index_def in self._col_to_attr_idx):
@@ -208,11 +205,14 @@ def _update_filter_ids(self, filter_by: Optional[Union[Filter, list[Filter]]] =
208205
raise ValueError(f"AttributeFilter instance referencing metric [{_filter.label}]")
209206
else:
210207
_filter.label = _str_to_obj_id(_filter.label) or _filter.label
211-
elif isinstance(_filter, MetricValueFilter) and isinstance(_filter.metric, str):
212-
if _filter.metric in self._col_to_metric_idx:
213-
# Metric is referenced by local_id which was already generated during creation of columns
214-
# When Metric filter contains ObjId reference, it does not need to be modified
215-
_filter.metric = self._metrics[self._col_to_metric_idx[_filter.metric]].local_id
208+
elif (
209+
isinstance(_filter, MetricValueFilter)
210+
and isinstance(_filter.metric, str)
211+
and _filter.metric in self._col_to_metric_idx
212+
):
213+
# Metric is referenced by local_id which was already generated during creation of columns
214+
# When Metric filter contains ObjId reference, it does not need to be modified
215+
_filter.metric = self._metrics[self._col_to_metric_idx[_filter.metric]].local_id
216216

217217
return filters
218218

gooddata-pandas/gooddata_pandas/result_convertor.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,7 @@ def _mapper(header: Any, header_idx: Optional[int]) -> Optional[str]:
347347
if "labelValue" in header["attributeHeader"]:
348348
label_value = header["attributeHeader"]["labelValue"]
349349
primary_label_value = header["attributeHeader"]["primaryLabelValue"]
350-
if use_primary_labels_in_attributes:
351-
label = primary_label_value
352-
else:
353-
label = label_value
350+
label = primary_label_value if use_primary_labels_in_attributes else label_value
354351
if header_idx is not None:
355352
if header_idx in primary_attribute_labels_mapping:
356353
primary_attribute_labels_mapping[header_idx][primary_label_value] = label_value

gooddata-sdk/gooddata_sdk/visualization.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,7 @@ def get_bucket_of_type(self, bucket_type: BucketType) -> VisualizationBucket:
618618
return VisualizationBucket({"items": [], "localIdentifier": _BUCKET_TYPE_TO_LOCAL_ID[bucket_type]})
619619

620620
def has_bucket_of_type(self, bucket_type: BucketType) -> bool:
621-
for b in self.buckets:
622-
if b.type == bucket_type:
623-
return True
624-
return False
621+
return any(b.type == bucket_type for b in self.buckets)
625622

626623
def has_row_and_col_totals(self) -> bool:
627624
row_bucket = self.get_bucket_of_type(BucketType.ROWS)

gooddata-sdk/tests/support/test_support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_wait_till_available_no_wait(test_config):
3737
sdk = GoodDataSdk.create(host_=test_config["host"], token_=test_config["token"])
3838
start_time = time.time()
3939
sdk.support.wait_till_available(3)
40-
assert 1000 > (time.time() - start_time)
40+
assert (time.time() - start_time) < 1000
4141

4242

4343
def test_wait_till_available_timeout(test_config):

0 commit comments

Comments
 (0)