Skip to content

Commit

Permalink
fix: BI-5542 bitrix user field filtering fix (#575)
Browse files Browse the repository at this point in the history
bitrix user field filtering fix
  • Loading branch information
juliarbkv authored Aug 12, 2024
1 parent c27c58f commit 1a70714
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import attr

from dl_constants.enums import UserDataType
from dl_core.fields import ResultSchema
from dl_core.fields import (
DirectCalculationSpec,
ResultSchema,
)
import dl_formula.core.nodes as formula_nodes
from dl_query_processing.compilation.primitives import CompiledFormulaInfo
from dl_query_processing.enums import ExecutionLevel
Expand All @@ -26,7 +29,11 @@ def is_pre_filter(self, formula: CompiledFormulaInfo) -> bool:
if not isinstance(expr, formula_nodes.OperationCall) or formula.original_field_id is None:
return False
field = self.result_schema.by_guid(formula.original_field_id)
if field.data_type in self.data_types and expr.name in self.expr_names:
if (
field.data_type in self.data_types
and expr.name in self.expr_names
and not (isinstance(field.calc_spec, DirectCalculationSpec) and field.source.startswith("UF_CRM_"))
):
# FIXME: Refactor this
return True
return False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DB_NAME,
SMART_TABLE_NAME,
TABLE_NAME,
UF_DATE_TABLE_NAME,
)


Expand Down Expand Up @@ -85,6 +86,19 @@ def dataset_params(self) -> dict:
)


class BitrixUfDateTablesDatasetTestBase(BitrixConnectionTestBase, DatasetTestBase):
@pytest.fixture(scope="class")
def dataset_params(self) -> dict:
return dict(
source_type=SOURCE_TYPE_BITRIX_GDS.name,
title=UF_DATE_TABLE_NAME,
parameters=dict(
db_name=DB_NAME,
table_name=UF_DATE_TABLE_NAME,
),
)


class BitrixDataApiTestBase(BitrixDatasetTestBase, StandardizedDataApiTestBase):
mutation_caches_enabled = False

Expand All @@ -101,3 +115,7 @@ def data_api_test_params(self) -> DataApiTestParams:

class BitrixSmartTablesDataApiTestBase(BitrixSmartTablesDatasetTestBase, StandardizedDataApiTestBase):
mutation_caches_enabled = False


class BitrixUfDateTablesDataApiTestBase(BitrixUfDateTablesDatasetTestBase, StandardizedDataApiTestBase):
mutation_caches_enabled = False
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@
DefaultConnectorDataRangeTestSuite,
DefaultConnectorDataResultTestSuite,
)
from dl_constants.enums import WhereClauseOperation
from dl_constants.enums import (
UserDataType,
WhereClauseOperation,
)
from dl_testing.regulated_test import RegulatedTestParams

from dl_connector_bitrix_gds_tests.ext.api.base import (
BitrixDataApiTestBase,
BitrixSmartTablesDataApiTestBase,
BitrixUfDateTablesDataApiTestBase,
)


Expand Down Expand Up @@ -67,3 +71,35 @@ def test_bitrix_string_to_date(
)
assert result_resp.status_code == 200, result_resp.json
assert get_data_rows(result_resp)


class TestBitrixUfDateTablesData(BitrixUfDateTablesDataApiTestBase):
def test_bitrix_user_field_filter(
self,
saved_dataset: Dataset,
data_api: SyncHttpDataApiV2,
) -> None:
ds = saved_dataset

ds.result_schema["uf_bitrix_dt_field"] = ds.field(
avatar_id=ds.source_avatars[0].id,
source=ds.find_field(title="UF_CRM_1715946731433").source,
data_type=UserDataType.date,
cast=UserDataType.date,
)
self.get_preview(ds, data_api)

result_resp = data_api.get_result(
dataset=ds,
fields=[ds.find_field(title="LEAD_ID")],
filters=[
ds.find_field(title="uf_bitrix_dt_field").filter(
op=WhereClauseOperation.BETWEEN,
values=["2024-05-17", "2024-05-20"],
)
],
order_by=[ds.find_field(title="LEAD_ID")],
)

assert result_resp.status_code == 200, result_resp.json
assert get_data_rows(result_resp) == [["5"], ["11"]]
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@
DB_NAME = "default"
TABLE_NAME = "crm_deal"
SMART_TABLE_NAME = "crm_dynamic_items_180"
UF_DATE_TABLE_NAME = "crm_lead_uf"

0 comments on commit 1a70714

Please sign in to comment.