You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are no guardrails in place to prevent a user from declaring a field called 'match', for example, which will require escaping in order to perform string restrictions.
Reproducibility
Include:
OS Linux
Python Version 3.9.18
MySQL Version 8.0.34
MySQL Deployment Strategy (local-native | local-docker | remote)
DataJoint Version 0.14.3
Minimum number of steps to reliably reproduce the issue
Complete error stack as a result of evaluating the above steps
I [77]: runtemp.py*idmatch+----++-------+11
(Total: 1)
*idmatch+----++-------+1131
(Total: 2)
---------------------------------------------------------------------------QuerySyntaxErrorTraceback (mostrecentcalllast)
File~/wrk/spyglass/temp-btl.py:1917print(BadField() &"id = 1")
18print(BadField() &"`match` = 1")
--->19print(BadField() &"match = 1")
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/expression.py:671, inQueryExpression.__repr__(self)
660def__repr__(self):
661""" 662 returns the string representation of a QueryExpression object e.g. ``str(q1)``. 663 (...) 666 :rtype: str 667 """668return (
669super().__repr__()
670ifconfig["loglevel"].lower() =="debug"-->671elseself.preview()
672 )
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/expression.py:676, inQueryExpression.preview(self, limit, width)
674defpreview(self, limit=None, width=None):
675""":return: a string of preview of the contents of the query."""-->676returnpreview(self, limit, width)
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/preview.py:13, inpreview(query_expression, limit, width)
11ifwidthisNone:
12width=config["display.width"]
--->13tuples=rel.fetch(limit=limit+1, format="array")
14has_more=len(tuples) >limit15tuples=tuples[:limit]
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/fetch.py:236, inFetch.__call__(self, offset, limit, order_by, format, as_dict, squeeze, download_path, *attrs)
234ret=return_values[0] iflen(attrs) ==1elsereturn_values235else: # fetch all attributes as a numpy.record_array or pandas.DataFrame-->236cur=self._expression.cursor(as_dict=as_dict)
237heading=self._expression.heading238ifas_dict:
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/expression.py:658, inQueryExpression.cursor(self, as_dict)
656sql=self.make_sql()
657logger.debug(sql)
-->658returnself.connection.query(sql, as_dict=as_dict)
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/connection.py:343, inConnection.query(self, query, args, as_dict, suppress_warnings, reconnect)
341cursor=self._conn.cursor(cursor=cursor_class)
342try:
-->343self._execute_query(cursor, query, args, suppress_warnings)
344excepterrors.LostConnectionError:
345ifnotreconnect:
File~/miniconda3/envs/rio/lib/python3.9/site-packages/datajoint/connection.py:299, inConnection._execute_query(cursor, query, args, suppress_warnings)
297cursor.execute(query, args)
298exceptclient.err.Erroraserr:
-->299raisetranslate_query_error(err, query)
QuerySyntaxError: ("You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 1)) ORDER BY `id` LIMIT 13' at line 1", 'SELECT `id`,`match` FROM `cbroz_temp`.`#bad_field` WHERE ( (match = 1)) ORDER BY `id` LIMIT 13')
Expected Behavior
A naive user might not be familiar with SQL keywords and expect the following to behave similarly.
CBroz1
changed the title
Reserved MySQL keywords as field names result in syntax errors on restriction
Reserved MySQL keywords as field names result in syntax errors on string restriction
Dec 2, 2024
This is a known problem that has been raised from time to time. DataJoint does not prevent users from using attribute names that are reserved words in MySQL, e.g. key, select, signal. Our decision was to address this correctly in all cases where datajoint has control over the syntax (e.g. declarations and queries), but not in cases where the user supplies their own SQL conditions as strings. This should be addressed in the documentation or perhaps in the error message.
Bug Report
Description
There are no guardrails in place to prevent a user from declaring a field called 'match', for example, which will require escaping in order to perform string restrictions.
Reproducibility
Include:
Reproduction
Error stack
Expected Behavior
A naive user might not be familiar with SQL keywords and expect the following to behave similarly.
DataJoint could potentially...
SyntaxError
, scan the where clause for reserved keywords and suggest the user restrict with a dictionary instead.Screenshots
n/a
Additional Research and Context
n/a
The text was updated successfully, but these errors were encountered: