Titan-Systems/titan

BUG : using square brackets instead of parentheses in compiled SQL

aleenprd opened this issue · 3 comments

snowflake.connector.errors.ProgrammingError: 001003: failed to execute sql, [ALTER NETWORK POLICY TITAN_TEST_NETWORK_POLICY SET allowed_network_rule_list = ['TITAN_TEST_NETWORK_RULE']]
=>

snowflake.connector.errors.ProgrammingError: 001003 (42000): SQL compilation error:
syntax error line 1 at position 79 unexpected '['.

Furthermore, you can't use direct resource object reference because it gets compiled to this SQL:
[ALTER NETWORK POLICY TITAN_TEST_NETWORK_POLICY SET allowed_network_rule_list = [Resource:TITAN_TEST_NETWORK_RULE]]

@neehhaa06

Uhm, it's how titan compiles the SQL, I am not writing the SQL myself. This is an error appearing on blueprint.apply.

The resource is defined in my code as:

titan_test_network_policy = NetworkPolicy(
    name="TITAN_TEST_NETWORK_POLICY",
    comment="Demo network policy for testing purposes of titan[core].",
    owner="SYSADMIN",
    allowed_network_rule_list=[titan_test_network_rule],
    blocked_network_rule_list=None,
    allowed_ip_list=None,
    blocked_ip_list=None,
    database=titan_test_db,
    schema=titan_test_schema,
)

As per the titan source code.

Am I misunderstanding something?

@neehhaa06 I already tried that as well. The result is simply that it gets compiled to snowflake.connector.errors.ProgrammingError: 001003: failed to execute sql, [ALTER NETWORK POLICY TITAN_TEST_NETWORK_POLICY SET allowed_network_rule_list = ['TITAN_TEST_NETWORK_RULE']] like I have already stated in my original issue. The problem is that it compiles the array with brackets which is not SQL syntax. Again, this means it results in the following error: snowflake.connector.errors.ProgrammingError: 001003: failed to execute sql, [ALTER NETWORK POLICY TITAN_TEST_NETWORK_POLICY SET allowed_network_rule_list = ['TITAN_TEST_NETWORK_RULE']] Please read carefully. You can recreate using this snippet:

titan_test_network_rule = NetworkRule(
    name="TITAN_TEST_NETWORK_RULE",
    type="IPV4",
    value_list=["some_ipv4_address"],
    mode="INGRESS",
    comment="Demo network rule resticting access to home Wifi only.",
    owner="SYSADMIN",
    database=titan_test_db,
    schema=titan_test_schema,
)

titan_test_network_policy = NetworkPolicy(
    name="TITAN_TEST_NETWORK_POLICY",
    comment="Demo network policy for testing purposes of titan[core].",
    owner="SYSADMIN",
    allowed_network_rule_list=["TITAN_TEST_NETWORK_RULE"],
    blocked_network_rule_list=None,
    allowed_ip_list=None,
    blocked_ip_list=None,
    database=titan_test_db,
    schema=titan_test_schema,
)

Furthermore, the documentation literally states that you can use it like this: allowed_network_rule_list=[NetworkRule(name="rule1"), NetworkRule(name="rule2")] (see link I posted previously).

    def __init__(
        self,
        name: str,
        allowed_network_rule_list: list[NetworkRule] = None,

PS: this is the source code as this particular resource is not documented in your wiki anyway.

teej commented

Fixed in v0.9