lore
lore copied to clipboard
Broken jinja2 templating in snowflake sql
Currently, Jinja2 templating is done here:
https://github.com/instacart/lore/blob/f4789b1439801cd5171df69d0d63d12060b52999/lore/io/connection.py#L413-L434
And this is how they are called:
https://github.com/instacart/lore/blob/f4789b1439801cd5171df69d0d63d12060b52999/lore/io/connection.py#L168-L169
The problem here is all the args are passed twice, one to jinja2, the other to snowflake connector.
It will break down right here, because nothing could be formated this way.
For example if we want to run
lore.io.analysis.execute(filename='somefile', job_type=self.job_type)
we will see processed_params
is not empty and breaks the program here:
https://github.com/snowflakedb/snowflake-connector-python/blob/83dfe771c5404657f2008fec15bf0386185b6d70/cursor.py#L491
https://github.com/instacart/lore/blob/cfca2b459e2b333b8400c0751be2856cedb5eedd/lore/io/connection.py#L436
The bindings (which is actually used in jinja2 template) is passed again in this function, in to snowflake connector's execute.
One suggestion is to give jinja2 template args a dict argument that works like kwargs, so these values will not interfere snowflake connector's execute method
@Curtis-Jiang-2020 makes sense. feel free to open a PR with this improvement.
In need of forensic audit of all aspect of Instacart rating system https://user-images.githubusercontent.com/80199202/204365583-76af8c36-49d8-4c8c-808f-0f8ad9b41bdc.MOV