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: errors during swagger api-docs generation #273

Merged
merged 3 commits into from
Jan 30, 2025
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 openedx_learning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Open edX Learning ("Learning Core").
"""

__version__ = "0.18.1"
__version__ = "0.18.2"
3 changes: 1 addition & 2 deletions openedx_tagging/core/tagging/rest_api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ class ObjectTagSerializer(ObjectTagMinimalSerializer):
class Meta:
model = ObjectTag
fields = ObjectTagMinimalSerializer.Meta.fields + [
# The taxonomy name
"name",
"export_id",
"taxonomy_id",
# If the Tag or Taxonomy has been deleted, this ObjectTag shouldn't be shown to users.
"is_deleted",
Expand Down
10 changes: 8 additions & 2 deletions openedx_tagging/core/tagging/rest_api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ def get_taxonomy(self) -> Taxonomy:
The current taxonomy is cached in the view.
"""
if not self._taxonomy:
taxonomy_id = int(self.kwargs["pk"])
taxonomy = get_taxonomy(taxonomy_id)
taxonomy_id = self.kwargs.get("pk")
taxonomy = get_taxonomy(int(taxonomy_id)) if taxonomy_id else None
if not taxonomy:
raise Http404("Taxonomy not found")
self.check_object_permissions(self.request, taxonomy)
Expand All @@ -799,6 +799,9 @@ def get_serializer_context(self):
context['request'] = self.request
serializer = self.serializer_class(self, context=context)

if getattr(self, 'swagger_fake_view', False):
# queryset just for schema generation metadata
return context
# Instead of checking permissions for each TagData instance, we just check them once for the whole taxonomy
# (since that's currently how our rules work). This might change if Tag-specific permissions are needed.
taxonomy = self.get_taxonomy()
Expand All @@ -814,6 +817,9 @@ def get_queryset(self) -> TagDataQuerySet:
"""
Builds and returns the queryset to be paginated.
"""
if getattr(self, 'swagger_fake_view', False):
# queryset just for schema generation metadata
return Taxonomy.objects.none() # type: ignore[return-value]
taxonomy = self.get_taxonomy()
parent_tag_value = self.request.query_params.get("parent_tag", None)
include_counts = "include_counts" in self.request.query_params
Expand Down