Skip to content

Conversation

grdsdev
Copy link
Contributor

@grdsdev grdsdev commented Sep 22, 2025

Summary

Implements the equivalent of the maxAffected method from postgrest-js library for the Python postgrest client.

  • ✅ Adds max_affected method to BaseFilterRequestBuilder class
  • ✅ Sets handling=strict and max-affected={value} preferences in Prefer header
  • ✅ Supports method chaining by returning self
  • ✅ Available in both sync and async FilterRequestBuilder classes
  • ✅ Comprehensive test coverage with 10 new tests

Changes

Implementation

  • Added max_affected(value: int) method to BaseFilterRequestBuilder in src/postgrest/base_request_builder.py
  • Method properly handles existing Prefer headers and avoids duplicating handling=strict
  • Follows Python naming conventions (max_affected vs maxAffected)

Tests

  • Unit tests: Test basic functionality, header handling edge cases, and method chaining
  • Integration tests: Test compatibility with update() and delete() operations
  • Tests added to both async and sync versions following existing patterns

Usage

# Set maximum affected rows for update operations
result = await client.from_('table').update({'field': 'value'}).max_affected(5).execute()

# Set maximum affected rows for delete operations  
result = await client.from_('table').delete().max_affected(10).execute()

# Works with method chaining
result = await client.from_('table').update({'field': 'value'}).eq('id', 1).max_affected(1).execute()

Test plan

  • All existing tests continue to pass (152/152)
  • New unit tests verify basic functionality and edge cases (8/8 passing)
  • New integration tests verify compatibility with update/delete (2/2 passing)
  • Pre-commit hooks pass with proper code formatting
  • Method available in both sync and async versions

Notes

  • Equivalent to maxAffected method in postgrest-js
  • Only works with PostgREST v13+ and PATCH/DELETE methods (documented in docstring)
  • No runtime validation - constraints documented in method docstring following JS version approach

🤖 Generated with Claude Code

Add max_affected method to BaseFilterRequestBuilder to set the maximum
number of rows that can be affected by PATCH and DELETE operations.

- Adds handling=strict and max-affected={value} to Prefer header
- Supports method chaining by returning self
- Available in both sync and async FilterRequestBuilder classes
- Includes comprehensive test coverage for all scenarios

Equivalent to maxAffected method in postgrest-js library.
Only works with PostgREST v13+ and PATCH/DELETE methods.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@grdsdev grdsdev requested a review from o-santi September 22, 2025 08:52
@coveralls
Copy link

Pull Request Test Coverage Report for Build 17909755902

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 7 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.04%) to 93.839%

Files with Coverage Reduction New Missed Lines %
src/postgrest/base_request_builder.py 7 89.07%
Totals Coverage Status
Change from base Build 17868301713: 0.04%
Covered Lines: 8681
Relevant Lines: 9251

💛 - Coveralls

@grdsdev grdsdev requested a review from a team September 22, 2025 08:59
@o-santi o-santi merged commit 3f75daf into main Sep 22, 2025
11 checks passed
@o-santi o-santi deleted the guilherme/clibs-380-postgrest-py-implement-maxaffected-method branch September 22, 2025 12:00
@github-actions github-actions bot mentioned this pull request Sep 22, 2025
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
grdsdev added a commit to supabase/supabase that referenced this pull request Sep 30, 2025
Add documentation for the new max_affected() method introduced in
supabase-py PR #1222. This method allows limiting the number of rows
that can be affected by update or delete operations.

Changes:
- Added max_affected() method documentation to supabase_py_v2.yml
- Included parameter details and usage notes
- Added two examples: one for update and one for delete operations
- Documented PostgREST v13+ requirement and PATCH/DELETE method limitation

Source: supabase/supabase-py#1222

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants