-
Notifications
You must be signed in to change notification settings - Fork 130
Broken jinja2 templating in snowflake sql #168
Copy link
Copy link
Open
Description
Currently, Jinja2 templating is done here:
Lines 413 to 434 in f4789b1
| def __prepare(self, sql=None, extract=None, filename=None, **kwargs): | |
| if extract is None: | |
| extract = filename | |
| if sql is None and extract is not None: | |
| sql_filename = Connection.path(extract, '.sql') | |
| template_filename = Connection.path(extract, '.sql.j2') | |
| if os.path.exists(sql_filename): | |
| logger.debug('READ SQL FILE: ' + sql_filename) | |
| if os.path.exists(template_filename): | |
| logger.warning('ignoring template with the same base file name') | |
| with open(sql_filename) as file: | |
| sql = file.read() | |
| elif os.path.exists(template_filename): | |
| logger.debug('READ SQL TEMPLATE: ' + template_filename) | |
| sql = jinja2_env.get_template(extract + '.sql.j2').render(**kwargs) | |
| else: | |
| raise IOError('There is no template or sql file for %s' % extract) | |
| # support mustache style bindings | |
| sql = re.sub(r'\{(\w+?)\}', r'%(\1)s', sql) | |
| return sql |
And this is how they are called:
Lines 168 to 169 in f4789b1
| def execute(self, sql=None, extract=None, filename=None, **kwargs): | |
| self.__execute(self.__prepare(sql=sql, extract=extract, filename=filename, **kwargs), kwargs) |
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:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels