Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
382e7563
Commit
382e7563
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Prevent SQL injections
parent
7872a099
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#78309
passed
4 years ago
Stage: test
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
arkindex_worker/cache.py
+8
-2
8 additions, 2 deletions
arkindex_worker/cache.py
arkindex_worker/worker.py
+9
-7
9 additions, 7 deletions
arkindex_worker/worker.py
tests/test_cache.py
+8
-1
8 additions, 1 deletion
tests/test_cache.py
with
25 additions
and
10 deletions
arkindex_worker/cache.py
+
8
−
2
View file @
382e7563
...
...
@@ -43,6 +43,12 @@ class LocalDB(object):
)
self
.
db
.
commit
()
def
fetch
(
self
,
table
,
where_clause
=
""
):
self
.
cursor
.
execute
(
f
"
SELECT * FROM
{
table
}
{
where_clause
}
"
)
def
fetch
(
self
,
table
,
where
=
[]):
sql
=
f
"
SELECT * FROM
{
table
}
"
if
where
:
sql
+=
"
WHERE
"
sql
+=
"
AND
"
.
join
(
[
f
"
{
field
}
{
operator
}
(?)
"
for
field
,
operator
,
_
in
where
]
)
self
.
cursor
.
execute
(
sql
,
[
value
for
_
,
_
,
value
in
where
])
return
self
.
cursor
.
fetchall
()
This diff is collapsed.
Click to expand it.
arkindex_worker/worker.py
+
9
−
7
View file @
382e7563
...
...
@@ -897,17 +897,19 @@ class ElementsWorker(BaseWorker):
"
type
"
,
"
worker_version
"
,
},
"
When using the local cache, you can only filter by
'
name
'
,
'
type
'
and/or
'
worker_version
'"
parent_id_hex
=
convert_str_uuid_to_hex
(
element
.
id
)
name_condition
=
f
"
AND name LIKE
'
%
{
name
}
%
'"
if
name
else
""
type_condition
=
f
"
AND type=
'
{
type
}
'"
if
type
else
""
worker_version_condition
=
(
f
"
AND worker_version_id=
'
{
convert_str_uuid_to_hex
(
worker_version
)
}
'"
conditions
=
[(
"
parent_id
"
,
"
=
"
,
convert_str_uuid_to_hex
(
element
.
id
))]
conditions
+=
[(
"
name
"
,
"
LIKE
"
,
f
"
%
{
name
}
%
"
)]
if
name
else
[]
conditions
+=
[(
"
type
"
,
"
=
"
,
type
)]
if
type
else
[]
conditions
+=
(
[(
"
worker_version_id
"
,
"
=
"
,
convert_str_uuid_to_hex
(
worker_version
))]
if
worker_version
else
""
else
[]
)
children
=
self
.
cache
.
fetch
(
"
elements
"
,
where
_clause
=
f
"
WHERE parent_id=
'
{
parent_id_hex
}
'
{
name_condition
}{
type_condition
}{
worker_version_condition
}
"
,
where
=
conditions
,
)
children
=
[
CachedElement
(
**
dict
(
child
))
for
child
in
children
]
else
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_cache.py
+
8
−
1
View file @
382e7563
...
...
@@ -146,6 +146,13 @@ def test_fetch_with_where():
cache
.
create_tables
()
rows
=
cache
.
fetch
(
"
elements
"
,
where_clause
=
f
"
WHERE parent_id=
'
{
convert_str_uuid_to_hex
(
'
12341234-1234-1234-1234-123412341234
'
)
}
'
AND name LIKE
'
%0%
'"
,
where
=
[
(
"
parent_id
"
,
"
=
"
,
convert_str_uuid_to_hex
(
"
12341234-1234-1234-1234-123412341234
"
),
),
(
"
name
"
,
"
LIKE
"
,
"
%0%
"
),
],
)
assert
[
CachedElement
(
**
dict
(
row
))
for
row
in
rows
]
==
[
ELEMENTS_TO_INSERT
[
0
]]
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment