Skip to content

Commit 51affce

Browse files
linter fixes
1 parent b3755ca commit 51affce

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

docs/reference/esql-query-builder.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ query = (
207207

208208
ES|QL, like most query languages, is vulnerable to [code injection attacks](https://en.wikipedia.org/wiki/Code_injection) if untrusted data provided by users is added to a query. To eliminate this risk, ES|QL allows untrusted data to be given separately from the query as parameters.
209209

210-
Continuing with the example above, let's assume that the application needs a `find_employee_by_name()` function that searches for the name given as an argument. If this argument is received by the application from users, then it is considered untrusted and cannot be added to the query directly. Here is how to code the function in a secure manner:
210+
Continuing with the example above, let's assume that the application needs a `find_employee_by_name()` function that searches for the name given as an argument. If this argument is received by the application from users, then it is considered untrusted and should not be added to the query directly. Here is how to code the function in a secure manner:
211211

212212
```python
213213
def find_employee_by_name(name):
@@ -219,7 +219,7 @@ def find_employee_by_name(name):
219219
return client.esql.query(query=str(query), params=[name])
220220
```
221221

222-
Here the part of the query in which the untrusted data needs to be inserted is replaced with a parameter, which in ES|QL is defined by the question mark. In Python the parameter is given as `E("?")` so that it is treated as an expression and not as a literal string.
222+
Here the part of the query in which the untrusted data needs to be inserted is replaced with a parameter, which in ES|QL is defined by the question mark. When using Python expressions, the parameter must be given as `E("?")` so that it is treated as an expression and not as a literal string.
223223

224224
The list of values given in the `params` argument to the query endpoint are assigned in order to the parameters defined in the query.
225225

elasticsearch/esql/esql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def _format_index(index: IndexType) -> str:
117117
return index._index._name if hasattr(index, "_index") else str(index)
118118

119119
@staticmethod
120-
def _format_id(id: FieldType, allow_patterns=False) -> str:
120+
def _format_id(id: FieldType, allow_patterns: bool = False) -> str:
121121
s = str(id) # in case it is an InstrumentedField
122122
if allow_patterns and "*" in s:
123123
return s # patterns cannot be escaped
@@ -696,7 +696,7 @@ def _render_internal(self) -> str:
696696
names = (
697697
""
698698
if not self._type_name and not self._pvalue_name
699-
else f' AS {self._format_id(self._type_name) or "type"}, {self._format_id(self._pvalue_name) or "pvalue"}'
699+
else f' AS {self._format_id(self._type_name or "type")}, {self._format_id(self._pvalue_name or "pvalue")}'
700700
)
701701
return f"CHANGE_POINT {self._value}{key}{names}"
702702

0 commit comments

Comments
 (0)