Skip to content

Commit

Permalink
fix: errors during swagger api-docs generation (#273)
Browse files Browse the repository at this point in the history
* ObjectTag.name is no longer a field, using export_id instead
* KeyError: 'pk'
* chore: bumps package version
* fix: swagger docs missing queryset issue

---------

Co-authored-by: Navin Karkera <navin@opencraft.com>
  • Loading branch information
pomegranited and navinkarkera authored Jan 30, 2025
1 parent 658191a commit 1223060
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
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

0 comments on commit 1223060

Please sign in to comment.