Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invocations of read_channel_metadata_from_db_file to expect a dict #8369

Merged
merged 1 commit into from
Sep 2, 2021
Merged
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
2 changes: 1 addition & 1 deletion kolibri/core/content/management/commands/scanforcontent.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def database_file_is_newer(self, channel_id, disk_path):
disk_channel = read_channel_metadata_from_db_file(disk_path)
db_channel = ChannelMetadata.objects.get(id=channel_id)
# the version in the primary database is older than the one on disk
return disk_channel.version > db_channel.version
return disk_channel["version"] > db_channel.version
except DatabaseError:
# problem with the database on disk; it can't be considered newer
return False
Expand Down
22 changes: 11 additions & 11 deletions kolibri/core/content/utils/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ def get_channels_for_data_folder(datafolder):
continue
channel_data = {
"path": path,
"id": channel.id,
"name": channel.name,
"description": channel.description,
"tagline": getattr(channel, "tagline", ""),
"thumbnail": channel.thumbnail,
"version": channel.version,
"root": channel.root_id,
"author": channel.author,
"last_updated": getattr(channel, "last_updated", None),
"lang_code": getattr(channel, "lang_code", None),
"lang_name": getattr(channel, "lang_name", None),
"id": channel["id"],
"name": channel["name"],
"description": channel["description"],
"tagline": channel.get("tagline", ""),
"thumbnail": channel["thumbnail"],
"version": channel["version"],
"root": channel["root_id"],
"author": channel["author"],
"last_updated": channel.get("last_updated"),
"lang_code": channel.get("lang_code"),
"lang_name": channel.get("lang_name"),
Comment on lines +124 to +134
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the inconsistency in getter style because some of these are supposed to throw value errors and others are supposed to return None if the items doesn't exist?

(Mainly just curious if this is part of an implicit required/optional API of some kind)

Copy link
Member Author

Choose a reason for hiding this comment

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

As it was 'like that when I got here' at this point, I am inferring - but I think these use of get versus direct key access is a result of newer fields being added that might be undefined in historic channel DB schema.

}
channels.append(channel_data)
return channels
Expand Down
2 changes: 1 addition & 1 deletion kolibri/core/tasks/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ def channeldiffstats(self, request):
channel_metadata = read_channel_metadata_from_db_file(
get_content_database_file_path(channel_id, drive.datafolder)
)
job_metadata["new_channel_version"] = channel_metadata.version
job_metadata["new_channel_version"] = channel_metadata["version"]
else:
raise serializers.ValidationError(
"'method' field should either be 'network' or 'disk'."
Expand Down