Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
a19ab485
Commit
a19ab485
authored
9 months ago
by
Valentin Rigal
Committed by
Erwan Rouchet
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Support exports version 8 in the load_export command
parent
da737565
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2317
Support exports version 8 in the load_export command
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/management/commands/load_export.py
+9
-5
9 additions, 5 deletions
arkindex/documents/management/commands/load_export.py
arkindex/documents/tests/commands/test_load_export.py
+8
-2
8 additions, 2 deletions
arkindex/documents/tests/commands/test_load_export.py
with
17 additions
and
7 deletions
arkindex/documents/management/commands/load_export.py
+
9
−
5
View file @
a19ab485
...
...
@@ -38,7 +38,8 @@ from arkindex.process.models import (
from
arkindex.training.models
import
Dataset
,
DatasetElement
,
DatasetSet
,
Model
from
arkindex.users.models
import
Role
,
User
EXPORT_VERSION
=
9
EXPORT_VERSION_MIN
=
8
EXPORT_VERSION_MAX
=
9
TABLE_NAMES
=
{
"
export_version
"
,
...
...
@@ -519,13 +520,16 @@ class Command(BaseCommand):
# Check database tables
db_results
=
self
.
db
.
execute
(
SQL_TABLES_QUERY
).
fetchall
()
if
not
set
([
table
[
"
name
"
]
for
table
in
db_results
])
==
TABLE_NAMES
:
raise
CommandError
(
f
"
The SQLite database
{
db_path
}
is not a correct Arkindex export
"
)
# Database's tables must be a superset of TABLE_NAMES, so we keep compatibility when removing things
if
(
missing
:
=
TABLE_NAMES
-
set
([
table
[
"
name
"
]
for
table
in
db_results
])):
raise
CommandError
(
f
"
The SQLite database
{
db_path
}
is missing some expected tables:
{
sorted
(
missing
)
}
"
)
# Check export version
db_results
=
self
.
db
.
execute
(
SQL_VERSION_QUERY
).
fetchall
()
if
len
(
db_results
)
!=
1
or
db_results
[
0
][
"
version
"
]
!=
EXPORT_VERSION
:
raise
CommandError
(
f
"
The SQLite database
{
db_path
}
does not have the correct export version
"
)
if
len
(
db_results
)
!=
1
or
not
(
EXPORT_VERSION_MIN
<=
db_results
[
0
][
"
version
"
]
<=
EXPORT_VERSION_MAX
):
raise
CommandError
(
f
"
The SQLite database
{
db_path
}
does not have a supported export version
"
)
# Retrieve corpus name
date
=
datetime
.
now
(
timezone
.
utc
).
strftime
(
"
%Y-%m-%d %H:%M
"
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/commands/test_load_export.py
+
8
−
2
View file @
a19ab485
...
...
@@ -100,7 +100,13 @@ class TestLoadExport(FixtureTestCase):
_
,
temp_file
=
tempfile
.
mkstemp
(
suffix
=
"
.db
"
)
with
self
.
assertRaises
(
CommandError
)
as
context
:
call_command
(
"
load_export
"
,
temp_file
,
"
--email
"
,
self
.
user
.
email
)
self
.
assertEqual
(
str
(
context
.
exception
),
f
"
The SQLite database
{
temp_file
}
is not a correct Arkindex export
"
)
self
.
assertEqual
(
str
(
context
.
exception
),
(
f
"
The SQLite database
{
temp_file
}
is missing some expected tables:
"
"
[
'
classification
'
,
'
dataset
'
,
'
dataset_element
'
,
'
element
'
,
"
"'
element_path
'
,
'
entity
'
,
'
entity_type
'
,
'
export_version
'
,
"
"'
image
'
,
'
image_server
'
,
'
metadata
'
,
'
transcription
'
,
"
"'
transcription_entity
'
,
'
worker_run
'
,
'
worker_version
'
]
"
))
def
test_invalid_version
(
self
):
_
,
temp_file
=
tempfile
.
mkstemp
(
suffix
=
"
.db
"
)
...
...
@@ -113,7 +119,7 @@ class TestLoadExport(FixtureTestCase):
with
self
.
assertRaises
(
CommandError
)
as
context
:
call_command
(
"
load_export
"
,
temp_file
,
"
--email
"
,
self
.
user
.
email
,
"
--corpus-name
"
,
"
My corpus
"
)
self
.
assertEqual
(
str
(
context
.
exception
),
f
"
The SQLite database
{
temp_file
}
does not have
the correct
export version
"
)
self
.
assertEqual
(
str
(
context
.
exception
),
f
"
The SQLite database
{
temp_file
}
does not have
a supported
export version
"
)
@patch
(
"
arkindex.documents.export.os.unlink
"
)
@patch
(
"
arkindex.project.aws.s3.Object
"
)
...
...
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