Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sdk-compliance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
symbols:
- AsyncGoTrueClient.on_auth_state_change
- SyncGoTrueClient.on_auth_state_change
auth.session.auto_refresh:

Check warning on line 112 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

auth.session.auto_refresh: marked implemented but has no registered symbols to verify
status: implemented
note: "Token refresh runs automatically as an internal background task controlled by the auto_refresh_token constructor option."

Expand Down Expand Up @@ -282,25 +282,25 @@
# ── Client ─────────────────────────────────────────────────────────────────

client.authentication_integration.third_party_auth: not_implemented
client.authentication_integration.cross_client_token_sync:

Check warning on line 285 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.authentication_integration.cross_client_token_sync: marked implemented but has no registered symbols to verify
status: implemented
note: "On SIGNED_IN, TOKEN_REFRESHED, and SIGNED_OUT events the Authorization header is updated and sub-clients (postgrest, storage, functions) are lazily recreated with the new token on their next access; realtime.set_auth() is called directly."
client.authentication_integration.oauth_flow_type:

Check warning on line 288 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.authentication_integration.oauth_flow_type: marked implemented but has no registered symbols to verify
status: implemented
note: "flow_type constructor parameter on the auth client."
client.authentication_integration.session_url_detection: not_implemented

client.session_management.custom_storage:

Check warning on line 293 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.session_management.custom_storage: marked implemented but has no registered symbols to verify
status: implemented
note: "storage parameter on the auth client accepts a custom async/sync storage backend."
client.session_management.persist_session:

Check warning on line 296 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.session_management.persist_session: marked implemented but has no registered symbols to verify
status: implemented
note: "persist_session constructor parameter on the auth client."

client.request_configuration.custom_http_client:

Check warning on line 300 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.request_configuration.custom_http_client: marked implemented but has no registered symbols to verify
status: implemented
note: "http_client parameter on client constructors accepts a custom httpx client."
client.request_configuration.global_headers:

Check warning on line 303 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

client.request_configuration.global_headers: marked implemented but has no registered symbols to verify
status: implemented
note: "headers parameter accepted by all sub-client constructors."

Expand Down Expand Up @@ -351,12 +351,12 @@
symbols:
- AsyncRequestBuilder.delete
- SyncRequestBuilder.delete
database.mutate.select_after_mutation:

Check warning on line 354 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

database.mutate.select_after_mutation: marked implemented but has no registered symbols to verify
status: implemented
note: "Chainable .select(*columns) after insert/update/upsert/delete — sets return=representation and adds a column selection query param. count and returning parameters also supported directly on each mutate method."

database.using_filters.eq: implemented

Check warning on line 358 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

database.using_filters.eq: marked implemented but has no registered symbols to verify
database.using_filters.neq: implemented

Check warning on line 359 in sdk-compliance.yaml

View workflow job for this annotation

GitHub Actions / validate / Check public API against capability matrix

database.using_filters.neq: marked implemented but has no registered symbols to verify
database.using_filters.gt: implemented
database.using_filters.gte: implemented
database.using_filters.lt: implemented
Expand Down Expand Up @@ -418,7 +418,10 @@
symbols:
- AsyncSelectRequestBuilder.maybe_single
- SyncSelectRequestBuilder.maybe_single
database.using_modifiers.strip_nulls: not_implemented
database.using_modifiers.strip_nulls:
status: implemented
symbols:
- BaseSelectRequestBuilder.strip_nulls
database.using_modifiers.format_csv:
status: implemented
symbols:
Expand Down
19 changes: 19 additions & 0 deletions src/postgrest/src/postgrest/base_request_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def __init__(
self.json = None if http_method in {"GET", "HEAD"} else json
self.auth = auth
self.retry_enabled = retry_enabled
self.strip_nulls = False

@overload
def send(
Expand All @@ -95,6 +96,14 @@ def send(

def send(self: RequestConfig[C], additional_headers: Headers):
additional_headers.update(self.headers)
if self.strip_nulls:
accept = additional_headers.get("Accept")
if accept == "application/vnd.pgrst.object+json":
additional_headers["Accept"] = f"{accept};nulls=stripped"
elif accept in (None, "application/json"):
additional_headers["Accept"] = (
"application/vnd.pgrst.array+json;nulls=stripped"
)
return self.session.request(
self.http_method,
str(self.path),
Expand Down Expand Up @@ -674,6 +683,16 @@ def range(
)
return self

def strip_nulls(self: Self) -> Self:
"""Strip null values from the response data.

Only available in PostgREST v11.2+.
"""
if self.request.headers.get("Accept") == "text/csv":
raise ValueError("strip_nulls() cannot be used with csv()")
self.request.strip_nulls = True
return self


class BaseRPCRequestBuilder(BaseSelectRequestBuilder):
def select(
Expand Down
22 changes: 22 additions & 0 deletions src/postgrest/tests/test_strip_nulls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from httpx import Client, MockTransport, Request, Response

from postgrest import SyncPostgrestClient


@pytest.mark.parametrize(
"single, expected",
[
(False, "application/vnd.pgrst.array+json;nulls=stripped"),
(True, "application/vnd.pgrst.object+json;nulls=stripped"),
],
)
def test_strip_nulls_sets_accept_header(single: bool, expected: str) -> None:
def handler(request: Request) -> Response:
assert request.headers["Accept"] == expected
return Response(200, json=[])

with Client(transport=MockTransport(handler)) as http:
client = SyncPostgrestClient("https://example.com", http_client=http)
query = client.from_("users").select("*").strip_nulls()
(query.single() if single else query).execute()
Loading