Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/5324.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adapted PulpImport/Export to allow update django-import-export==4.x.
4 changes: 4 additions & 0 deletions pulpcore/app/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def _write_export(the_tarfile, resource, dest_dir=None):
# the data in batches to memory and concatenate the json lists via string manipulation.
with tempfile.NamedTemporaryFile(dir=".", mode="w", encoding="utf8") as temp_file:
if isinstance(resource.queryset, QuerySet):
# If we don't have any of "these" - skip writing
if resource.queryset.count() == 0:
return

temp_file.write("[")

def process_batch(batch):
Expand Down
6 changes: 3 additions & 3 deletions pulpcore/app/modelresource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def before_import_row(self, row, **kwargs):
# the export converts None to blank strings but sha384 and sha512 have unique constraints
# that get triggered if they are blank. convert checksums back into None if they are blank.
for checksum in ALL_KNOWN_CONTENT_CHECKSUMS:
if row[checksum] == "":
row[checksum] = None
if row[checksum] == "" or checksum not in settings.ALLOWED_CONTENT_CHECKSUMS:
del row[checksum]
Comment on lines +65 to +66
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Random unrelated question: Do we recalculate missing checksums on import? Or do both systems need the same setting there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine question, and the answers are "no we don't" and "...huh." I expect that, "in the wild", systems being exported-to have the same settings as the system being exported-from, so it just never came up. But it's a de-facto standard, not a de-jure one :)


def set_up_queryset(self):
"""
Expand Down Expand Up @@ -109,7 +109,7 @@ def get_queryset(self, value, row, *args, **kwargs):
return qs

def render(self, value, obj=None, **kwargs):
return value.sha256
return value.sha256 if value else ""


class ContentArtifactResource(QueryModelResource):
Expand Down
6 changes: 6 additions & 0 deletions pulpcore/app/tasks/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def _import_file(fpath, resource_class, retry=False):
"""
try:
log.info(f"Importing file {fpath}.")
if not os.path.isfile(fpath):
log.info("...empty - skipping.")
return []
with open(fpath, "r") as json_file:
resource = resource_class()
log.info(f"...Importing resource {resource.__class__.__name__}.")
Expand All @@ -241,6 +244,8 @@ def _import_file(fpath, resource_class, retry=False):
# overlapping content.
for batch_str in _impfile_iterator(json_file):
data = Dataset().load(StringIO(batch_str))
if not data:
return []
if retry:
curr_attempt = 1

Expand Down Expand Up @@ -272,6 +277,7 @@ def _import_file(fpath, resource_class, retry=False):
try:
a_result = resource.import_data(data, raise_errors=True)
except Exception as e: # noqa log on ANY exception and then re-raise
log.error(e)
log.error(f"FATAL import-failure importing {fpath}")
raise
else:
Expand Down
3 changes: 3 additions & 0 deletions pulpcore/plugin/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def set_up_queryset(self):
def dehydrate_pulp_domain(self, content):
return str(content.pulp_domain_id)

def render(self, value, obj=None, **kwargs):
return super().render(value, obj, coerce_to_string=False, **kwargs)

def __init__(self, repo_version=None):
self.repo_version = repo_version
if repo_version:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"Django~=4.2.0", # LTS version, switch only if we have a compelling reason to".
"django-filter>=23.1,<=25.1", # Uses CalVer, not released often https://github.com/carltongibson/django-filter
"django-guid>=3.3.0,<3.6", # Looks like only bugfixes in z-Stream.
"django-import-export>=2.9,<3.4.0",
"django-import-export>=4.3,<5.0",
"django-lifecycle>=1.0,<=1.2.4",
"djangorestframework>=3.14.0,<=3.16.1",
"djangorestframework-queryfields>=1.0,<=1.1.0",
Expand All @@ -59,7 +59,7 @@ dependencies = [
"python-gnupg>=0.5.0,<0.6", # Looks like only bugfixes in z-Stream [changelog only in git]
"PyYAML>=5.1.1,<6.1", # Looks like only bugfixes in z-Stream.
"redis>=4.3.0,<6.5", # Looks like only bugfixes in z-Stream.
"tablib>=3.5.0,<3.6", # 3.6.0 breaks with import export. Not sure about semver.
"tablib>=3.7.0,<4.0", # 3.6.0 breaks with import export. Not sure about semver.
"url-normalize>=1.4.3,<2.3", # SemVer. https://github.com/niksite/url-normalize/blob/master/CHANGELOG.md#changelog
"uuid6>=2023.5.2,<=2025.0.1",
"whitenoise>=5.0,<6.12.0",
Expand Down