fix: Admin UI pagination proxy compatibility and fix for count accuracy#2846
fix: Admin UI pagination proxy compatibility and fix for count accuracy#2846crivetimihai merged 5 commits intomainfrom
Conversation
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
Signed-off-by: Madhav Kandukuri <madhav165@gmail.com>
d16240e to
d022ddc
Compare
d2a04c5 to
3d96b39
Compare
ReviewRebased onto main (clean, no conflicts). All 15 new/modified tests pass. Changes look good
Minor issues (non-blocking)
|
- Recompute total_pages, has_next, has_prev, and page in _adjust_pagination_for_conversion_failures to avoid stale UI state - Fix test_auth_cache_import_error: patch the already-imported function reference instead of sys.modules (module-level import was already resolved) - Fix test_redis_available_cache_hit: patch get_redis_client in the consuming module, not the source module - Rename misleading test to test_offset_paginate_page_not_clamped_when_no_items - Add tests for derived pagination field recomputation Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
- Remove page clamping from _adjust_pagination_for_conversion_failures since data was already fetched for the original page; clamping would make metadata claim a different page than what is displayed - Use request.scope root_path for tool-ops partial endpoint base_url instead of settings.app_root_path, consistent with all other partials Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Additional fixes pushedTwo follow-up commits added after review: Commit 4:
|
…cy (#2846) * fix baseUrl Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix x-data base-url Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * add new tests Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix: complete pagination adjustment and fix broken mock targets - Recompute total_pages, has_next, has_prev, and page in _adjust_pagination_for_conversion_failures to avoid stale UI state - Fix test_auth_cache_import_error: patch the already-imported function reference instead of sys.modules (module-level import was already resolved) - Fix test_redis_available_cache_hit: patch get_redis_client in the consuming module, not the source module - Rename misleading test to test_offset_paginate_page_not_clamped_when_no_items - Add tests for derived pagination field recomputation Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: do not clamp page after conversion and use root_path for tool-ops - Remove page clamping from _adjust_pagination_for_conversion_failures since data was already fetched for the original page; clamping would make metadata claim a different page than what is displayed - Use request.scope root_path for tool-ops partial endpoint base_url instead of settings.app_root_path, consistent with all other partials Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
…cy (#2846) * fix baseUrl Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix x-data base-url Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * add new tests Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix: complete pagination adjustment and fix broken mock targets - Recompute total_pages, has_next, has_prev, and page in _adjust_pagination_for_conversion_failures to avoid stale UI state - Fix test_auth_cache_import_error: patch the already-imported function reference instead of sys.modules (module-level import was already resolved) - Fix test_redis_available_cache_hit: patch get_redis_client in the consuming module, not the source module - Rename misleading test to test_offset_paginate_page_not_clamped_when_no_items - Add tests for derived pagination field recomputation Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: do not clamp page after conversion and use root_path for tool-ops - Remove page clamping from _adjust_pagination_for_conversion_failures since data was already fetched for the original page; clamping would make metadata claim a different page than what is displayed - Use request.scope root_path for tool-ops partial endpoint base_url instead of settings.app_root_path, consistent with all other partials Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com> Signed-off-by: Vishu Bhatnagar <vishu.bhatnagar@ibm.com>
…cy (IBM#2846) * fix baseUrl Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix x-data base-url Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * add new tests Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> * fix: complete pagination adjustment and fix broken mock targets - Recompute total_pages, has_next, has_prev, and page in _adjust_pagination_for_conversion_failures to avoid stale UI state - Fix test_auth_cache_import_error: patch the already-imported function reference instead of sys.modules (module-level import was already resolved) - Fix test_redis_available_cache_hit: patch get_redis_client in the consuming module, not the source module - Rename misleading test to test_offset_paginate_page_not_clamped_when_no_items - Add tests for derived pagination field recomputation Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: do not clamp page after conversion and use root_path for tool-ops - Remove page clamping from _adjust_pagination_for_conversion_failures since data was already fetched for the original page; clamping would make metadata claim a different page than what is displayed - Use request.scope root_path for tool-ops partial endpoint base_url instead of settings.app_root_path, consistent with all other partials Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Madhav Kandukuri <madhav165@gmail.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
Fixes #2851 When items fail Pydantic validation during admin list views, the pagination 'Showing X - Y of Z' display was incorrect. The server adjusted total_items (Z) but the X-Y range was computed client-side using requested items, not actual rendered count. Changes: - Add optional page_items field to PaginationMeta schema - Update _adjust_pagination_for_conversion_failures() to set page_items - Update 6 admin partial endpoints to pass rendered item count - Update pagination_controls.html to use page_items when available - Update tests to match new function signature Example: 20 items requested, 2 fail conversion - Before: 'Showing 1 - 20 of 98 items' (18 rows displayed) - After: 'Showing 1 - 18 of 98 items' (18 rows displayed) Builds on PR #2846 which introduced _adjust_pagination_for_conversion_failures() Signed-off-by: SuciuDaniel <Daniel.Vasile.Suciu@ibm.com>
Fixes #2851 When items fail Pydantic validation during admin list views, the pagination 'Showing X - Y of Z' display was incorrect. The server adjusted total_items (Z) but the X-Y range was computed client-side using requested items, not actual rendered count. Changes: - Add optional page_items field to PaginationMeta schema - Update _adjust_pagination_for_conversion_failures() to set page_items - Update 6 admin partial endpoints to pass rendered item count - Update pagination_controls.html to use page_items when available - Update tests to match new function signature Example: 20 items requested, 2 fail conversion - Before: 'Showing 1 - 20 of 98 items' (18 rows displayed) - After: 'Showing 1 - 18 of 98 items' (18 rows displayed) Builds on PR #2846 which introduced _adjust_pagination_for_conversion_failures() Signed-off-by: SuciuDaniel <Daniel.Vasile.Suciu@ibm.com>
…3238) Fixes #2851 When items fail Pydantic validation during admin list views, the pagination 'Showing X - Y of Z' display was incorrect. The server adjusted total_items (Z) but the X-Y range was computed client-side using requested items, not actual rendered count. Changes: - Add optional page_items field to PaginationMeta schema - Update _adjust_pagination_for_conversion_failures() to set page_items - Update 6 admin partial endpoints to pass rendered item count - Update pagination_controls.html to use page_items when available - Update tests to match new function signature Example: 20 items requested, 2 fail conversion - Before: 'Showing 1 - 20 of 98 items' (18 rows displayed) - After: 'Showing 1 - 18 of 98 items' (18 rows displayed) Builds on PR #2846 which introduced _adjust_pagination_for_conversion_failures() Signed-off-by: SuciuDaniel <Daniel.Vasile.Suciu@ibm.com>
…3238) Fixes #2851 When items fail Pydantic validation during admin list views, the pagination 'Showing X - Y of Z' display was incorrect. The server adjusted total_items (Z) but the X-Y range was computed client-side using requested items, not actual rendered count. Changes: - Add optional page_items field to PaginationMeta schema - Update _adjust_pagination_for_conversion_failures() to set page_items - Update 6 admin partial endpoints to pass rendered item count - Update pagination_controls.html to use page_items when available - Update tests to match new function signature Example: 20 items requested, 2 fail conversion - Before: 'Showing 1 - 20 of 98 items' (18 rows displayed) - After: 'Showing 1 - 18 of 98 items' (18 rows displayed) Builds on PR #2846 which introduced _adjust_pagination_for_conversion_failures() Signed-off-by: SuciuDaniel <Daniel.Vasile.Suciu@ibm.com>
…3238) Fixes #2851 When items fail Pydantic validation during admin list views, the pagination 'Showing X - Y of Z' display was incorrect. The server adjusted total_items (Z) but the X-Y range was computed client-side using requested items, not actual rendered count. Changes: - Add optional page_items field to PaginationMeta schema - Update _adjust_pagination_for_conversion_failures() to set page_items - Update 6 admin partial endpoints to pass rendered item count - Update pagination_controls.html to use page_items when available - Update tests to match new function signature Example: 20 items requested, 2 fail conversion - Before: 'Showing 1 - 20 of 98 items' (18 rows displayed) - After: 'Showing 1 - 18 of 98 items' (18 rows displayed) Builds on PR #2846 which introduced _adjust_pagination_for_conversion_failures() Signed-off-by: SuciuDaniel <Daniel.Vasile.Suciu@ibm.com> Signed-off-by: Yosief Eyob <yosiefogbazion@gmail.com>
🐛 Bug-fix PR
Fixes #2845
Summary
x-dataattribute corruption when a reverse proxy rewrites URLs in the response body by movingbase_urlfrom inline JavaScript to adata-*attributerequest.scope["root_path"]instead of hardcodedsettings.app_root_pathfor HTMX partial endpoint URLs so proxy path rewriting is respectedtotal_itemswhen DB rows fail Pydantic conversion so "Showing X of Y" counts match actual displayed itemspagetototal_pagesinoffset_paginateto avoid empty results when a page number exceeds available pagestotalPagesis 0 and show "No items found" for empty result setsdatetime.now()(local time) instead of UTC-based naive datetimesChanges
mcpgateway/templates/pagination_controls.html{{ base_url }}from inside thex-dataJavaScript expression to adata-base-urlHTML attribute on the outer<div>. The Alpineinit()method reads it viathis.baseUrl = $el.dataset.baseUrl. This prevents proxy URL rewriting from corrupting thex-data="..."attribute boundary.new URL('{{ base_url }}', ...)inloadPage()withnew URL(this.baseUrl, ...).<template x-if="totalPages > 0">so they are hidden for empty results.totalItems === 0instead of "Showing 1 - 0 of 0 items".<script>block).mcpgateway/admin.py_adjust_pagination_for_conversion_failures()helper that decrementspagination.total_itemsby the number of rows that fail DB-to-Pydantic conversion.settings.app_root_pathwithrequest.scope.get("root_path", "")when constructingbase_urlin all partial endpoints (servers, tools, prompts, gateways, resources, a2a agents, users).mcpgateway/utils/pagination.pypagetototal_pageswhentotal_pages > 0to prevent out-of-range offsets returning empty results.tests/unit/mcpgateway/utils/test_pagination.pytests/unit/mcpgateway/services/test_token_storage_service.pytest_is_token_expired_naive_datetime: usedatetime.now(timezone.utc).replace(tzinfo=None)instead ofdatetime.now()to create a naive datetime that represents UTC.tests/unit/mcpgateway/routers/test_log_search.pytest_aggregate_custom_windows_adds_timezone_to_naive_earliest_log: samedatetime.now()to UTC-based naive datetime fix.tests/unit/mcpgateway/test_db.pytest_email_team_invitation_is_expired_handles_timezone_mismatch,test_email_team_join_request_is_expired_handles_timezone_mismatch_now_naive,test_pending_user_approval_is_expired_handles_timezone_mismatch_now_naive,test_sso_auth_session_is_expired_handles_timezone_mismatch_now_naive): monkeypatchedutc_nowlambdas now returndatetime.now(timezone.utc).replace(tzinfo=None, microsecond=0)instead ofdatetime.now().replace(microsecond=0).uv.lockpytest-instafaildev dependency.🧪 Verification
make lintmake test📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit)