Skip to content

Commit

Permalink
Fix AuthConfigBase so its instances always evaluate to True in bool c…
Browse files Browse the repository at this point in the history
…ontext; change docs to suggest direct inheritance from AuthBase
  • Loading branch information
burnash committed May 22, 2024
1 parent b1e0f77 commit 96c0fe8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dlt/sources/helpers/rest_client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ class AuthConfigBase(AuthBase, CredentialsConfiguration):
configurable via env variables or toml files
"""

pass
def __bool__(self) -> bool:
# This is needed to avoid AuthConfigBase-derived classes
# which do not implement CredentialsConfiguration interface
# to be evaluated as False in requests.sessions.Session.prepare_request()
return True


@configspec
Expand Down
8 changes: 4 additions & 4 deletions docs/website/docs/general-usage/http/rest-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ The available authentication methods are defined in the `dlt.sources.helpers.res
- [APIKeyAuth](#api-key-authentication)
- [HttpBasicAuth](#http-basic-authentication)

For specific use cases, you can [implement custom authentication](#implementing-custom-authentication) by subclassing the `AuthConfigBase` class.
For specific use cases, you can [implement custom authentication](#implementing-custom-authentication) by subclassing the `AuthBase` class from the Requests library.

### Bearer token authentication

Expand Down Expand Up @@ -479,12 +479,12 @@ response = client.get("/protected/resource")

### Implementing custom authentication

You can implement custom authentication by subclassing the `AuthConfigBase` class and implementing the `__call__` method:
You can implement custom authentication by subclassing the `AuthBase` class and implementing the `__call__` method:

```py
from dlt.sources.helpers.rest_client.auth import AuthConfigBase
from requests.auth import AuthBase

class CustomAuth(AuthConfigBase):
class CustomAuth(AuthBase):
def __init__(self, token):
self.token = token

Expand Down

0 comments on commit 96c0fe8

Please sign in to comment.