Skip to content

Commit 31b150e

Browse files
committed
[PULP-817] Adjustments to make imp/exp work with django-imp-exp 4.x.
closes #5324.
1 parent 691c1c3 commit 31b150e

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

CHANGES/5324.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Adapted PulpImport/Export to allow update django-import-export==4.x.

pulpcore/app/importexport.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def _write_export(the_tarfile, resource, dest_dir=None):
4848
# the data in batches to memory and concatenate the json lists via string manipulation.
4949
with tempfile.NamedTemporaryFile(dir=".", mode="w", encoding="utf8") as temp_file:
5050
if isinstance(resource.queryset, QuerySet):
51+
# If we don't have any of "these" - skip writing
52+
if resource.queryset.count() == 0:
53+
return
54+
5155
temp_file.write("[")
5256

5357
def process_batch(batch):

pulpcore/app/modelresource.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def before_import_row(self, row, **kwargs):
6262
# the export converts None to blank strings but sha384 and sha512 have unique constraints
6363
# that get triggered if they are blank. convert checksums back into None if they are blank.
6464
for checksum in ALL_KNOWN_CONTENT_CHECKSUMS:
65-
if row[checksum] == "":
66-
row[checksum] = None
65+
if row[checksum] == "" or checksum not in settings.ALLOWED_CONTENT_CHECKSUMS:
66+
del row[checksum]
6767

6868
def set_up_queryset(self):
6969
"""
@@ -109,7 +109,7 @@ def get_queryset(self, value, row, *args, **kwargs):
109109
return qs
110110

111111
def render(self, value, obj=None, **kwargs):
112-
return value.sha256
112+
return value.sha256 if value else ""
113113

114114

115115
class ContentArtifactResource(QueryModelResource):

pulpcore/app/tasks/importer.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ def _import_file(fpath, resource_class, retry=False):
233233
"""
234234
try:
235235
log.info(f"Importing file {fpath}.")
236+
if not os.path.isfile(fpath):
237+
log.info("...empty - skipping.")
238+
return []
236239
with open(fpath, "r") as json_file:
237240
resource = resource_class()
238241
log.info(f"...Importing resource {resource.__class__.__name__}.")
@@ -241,6 +244,8 @@ def _import_file(fpath, resource_class, retry=False):
241244
# overlapping content.
242245
for batch_str in _impfile_iterator(json_file):
243246
data = Dataset().load(StringIO(batch_str))
247+
if not data:
248+
return []
244249
if retry:
245250
curr_attempt = 1
246251

@@ -272,6 +277,7 @@ def _import_file(fpath, resource_class, retry=False):
272277
try:
273278
a_result = resource.import_data(data, raise_errors=True)
274279
except Exception as e: # noqa log on ANY exception and then re-raise
280+
log.error(e)
275281
log.error(f"FATAL import-failure importing {fpath}")
276282
raise
277283
else:

pulpcore/plugin/importexport.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def set_up_queryset(self):
4141
def dehydrate_pulp_domain(self, content):
4242
return str(content.pulp_domain_id)
4343

44+
def render(self, value, obj=None, **kwargs):
45+
return super().render(value, obj, coerce_to_string=False, **kwargs)
46+
4447
def __init__(self, repo_version=None):
4548
self.repo_version = repo_version
4649
if repo_version:

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dependencies = [
3535
"Django~=4.2.0", # LTS version, switch only if we have a compelling reason to".
3636
"django-filter>=23.1,<=25.1", # Uses CalVer, not released often https://github.com/carltongibson/django-filter
3737
"django-guid>=3.3.0,<3.6", # Looks like only bugfixes in z-Stream.
38-
"django-import-export>=2.9,<3.4.0",
38+
"django-import-export>=4.3,<5.0",
3939
"django-lifecycle>=1.0,<=1.2.4",
4040
"djangorestframework>=3.14.0,<=3.16.1",
4141
"djangorestframework-queryfields>=1.0,<=1.1.0",
@@ -59,7 +59,7 @@ dependencies = [
5959
"python-gnupg>=0.5.0,<0.6", # Looks like only bugfixes in z-Stream [changelog only in git]
6060
"PyYAML>=5.1.1,<6.1", # Looks like only bugfixes in z-Stream.
6161
"redis>=4.3.0,<6.5", # Looks like only bugfixes in z-Stream.
62-
"tablib>=3.5.0,<3.6", # 3.6.0 breaks with import export. Not sure about semver.
62+
"tablib>=3.8.0,<4.0", # 3.6.0 breaks with import export. Not sure about semver.
6363
"url-normalize>=1.4.3,<2.3", # SemVer. https://github.com/niksite/url-normalize/blob/master/CHANGELOG.md#changelog
6464
"uuid6>=2023.5.2,<=2025.0.1",
6565
"whitenoise>=5.0,<6.12.0",

0 commit comments

Comments
 (0)