Skip to content

Commit 1223060

Browse files
fix: errors during swagger api-docs generation (#273)
* 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 <[email protected]>
1 parent 658191a commit 1223060

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

openedx_learning/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Open edX Learning ("Learning Core").
33
"""
44

5-
__version__ = "0.18.1"
5+
__version__ = "0.18.2"

openedx_tagging/core/tagging/rest_api/v1/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ class ObjectTagSerializer(ObjectTagMinimalSerializer):
157157
class Meta:
158158
model = ObjectTag
159159
fields = ObjectTagMinimalSerializer.Meta.fields + [
160-
# The taxonomy name
161-
"name",
160+
"export_id",
162161
"taxonomy_id",
163162
# If the Tag or Taxonomy has been deleted, this ObjectTag shouldn't be shown to users.
164163
"is_deleted",

openedx_tagging/core/tagging/rest_api/v1/views.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,8 +782,8 @@ def get_taxonomy(self) -> Taxonomy:
782782
The current taxonomy is cached in the view.
783783
"""
784784
if not self._taxonomy:
785-
taxonomy_id = int(self.kwargs["pk"])
786-
taxonomy = get_taxonomy(taxonomy_id)
785+
taxonomy_id = self.kwargs.get("pk")
786+
taxonomy = get_taxonomy(int(taxonomy_id)) if taxonomy_id else None
787787
if not taxonomy:
788788
raise Http404("Taxonomy not found")
789789
self.check_object_permissions(self.request, taxonomy)
@@ -799,6 +799,9 @@ def get_serializer_context(self):
799799
context['request'] = self.request
800800
serializer = self.serializer_class(self, context=context)
801801

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

0 commit comments

Comments
 (0)