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

list_user接口:page参数超过用户数量出现返回异常 #595

Open
Canway-shiisa opened this issue Jul 28, 2022 · 4 comments
Open
Assignees
Labels
canway 需求来源为嘉为侧 Layer: api Api module related Priority: Low Sign: help wanted Extra attention is needed Type: bug Something isn't working

Comments

@Canway-shiisa
Copy link
Contributor

问题详细描述

  • 调用用户管理list_user接口时,如果page参数传递超过用户数量的值,接口会返回404,而不是空或者没有数据的相关提示,比较容易误导开发者:
  • 异常返回图示:
    image

版本

  • 现有的最新版本仍然存在该问题
@wklken wklken assigned nannan00 and unassigned wklken Jul 28, 2022
@wklken wklken added Type: bug Something isn't working Priority: Middlum Middlum priority Layer: api Api module related labels Jul 28, 2022
@wklken
Copy link
Collaborator

wklken commented Sep 27, 2022

drf pagination默认的做法, 如果要处理, 需要改StandardResultsSetPagination => 但是, 返回结果中count必须保持正确(比较复杂)

ERROR [2022-09-27 14:35:42,573] unknown exception while handling the request, detail={'error': 'unknown', 'path': '/api/v2/profiles/', 'method': 'GET', 'query_params': <QueryDict: {'page': ['2'], 'page_size': ['100']}>, 'request_id': None}
Traceback (most recent call last):
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/rest_framework/pagination.py", line 204, in paginate_queryset
    self.page = paginator.page(page_number)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/django/core/paginator.py", line 76, in page
    number = self.validate_number(number)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/django/core/paginator.py", line 58, in validate_number
    raise EmptyPage(_('That page contains no results'))
django.core.paginator.EmptyPage: 本页结果为空

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/root/workspace/tx/wklken/bk-user/src/api/bkuser_core/profiles/v2/views.py", line 198, in list
    page = self.paginate_queryset(queryset)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/rest_framework/generics.py", line 171, in paginate_queryset
    return self.paginator.paginate_queryset(queryset, self.request, view=self)
  File "/root/workspace/tx/wklken/bk-user/src/api/bkuser_core/apis/v2/viewset.py", line 49, in paginate_queryset
    return super().paginate_queryset(queryset, request, view)
  File "/root/.pyenv/versions/bk-user/lib/python3.6/site-packages/rest_framework/pagination.py", line 209, in paginate_queryset
    raise NotFound(msg)
rest_framework.exceptions.NotFound: 无效页面。

@wklken wklken added the Sign: help wanted Extra attention is needed label Oct 19, 2022
@nannan00 nannan00 mentioned this issue Nov 10, 2022
34 tasks
@wklken wklken added Priority: Low and removed Priority: Middlum Middlum priority labels Nov 14, 2022
@wklken
Copy link
Collaborator

wklken commented Nov 14, 2022

降低优先级, 优先看下/api/v3中能处理这种场景, /api/v2暂不处理

@Canway-shiisa Canway-shiisa added the canway 需求来源为嘉为侧 label Mar 28, 2023
@Canway-shiisa
Copy link
Contributor Author

list_department同样存在问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
canway 需求来源为嘉为侧 Layer: api Api module related Priority: Low Sign: help wanted Extra attention is needed Type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants