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

Error importing ClientOptions from supabase #682

Closed
dantheman0207 opened this issue Feb 4, 2024 · 5 comments
Closed

Error importing ClientOptions from supabase #682

dantheman0207 opened this issue Feb 4, 2024 · 5 comments
Labels
bug Something isn't working
Milestone

Comments

@dantheman0207
Copy link

Describe the bug
I get this error: ImportError: cannot import name 'ClientOptions' from 'supabase'

To Reproduce
This is my code:

from supabase import create_client, Client, ClientOptions
from .config import Settings

settings = Settings()

def get_supabase(jwt: str = None) -> Client:
    if jwt:
        return create_client(
            settings.SUPABASE_URL,
            settings.SUPABASE_KEY,
            options=ClientOptions(
                headers={"Authorization": f"Bearer {jwt}"}
            )
        )
    else:
        return create_client(settings.SUPABASE_URL, settings.SUPABASE_KEY)

Expected behavior
This is using the exact code described in the docs. You can see a screenshot of it below. This import should work as documented.

Screenshots
Screenshot 2024-02-04 at 15 09 09

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.2.1
  • Browser: Safari
  • Version:
    • supabase==2.3.4
    • Python 3.11.7
    • Using virtualenv

Additional context
I am trying to set the header to the user's JWT auth token so I can implement RLS policies, as this will prevent me from writing a bunch of backend code to authorize access.

@Atticuszz
Copy link

async def create(
      cls,
      supabase_url: str,
      supabase_key: str,
      options: ClientOptions = ClientOptions(),
  ):
      client = cls(supabase_url, supabase_key, options)
      client._auth_token = await client._get_token_header()
      return client

  

  @property
  def postgrest(self):
      if self._postgrest is None:
          self.options.headers.update(self._auth_token)
          self._postgrest = self._init_postgrest_client(
              rest_url=self.rest_url,
              headers=self.options.headers,
              schema=self.options.schema,
              timeout=self.options.postgrest_client_timeout,
          )

      return self._postgrest

the code in repo
reset the your jwt by client._auth_token = await client._get_token_header(),so it occured as you said

@dantheman0207
Copy link
Author

@Atticuszz I don't want to reset the JWT, I want to use a specific JWT associated with the user using my API (so I can take advantage of RLS policies).

I see you're still using the ClientOptions in your example. The error is not in my code but in the actual import of ClientOptions. Based on the docs I should be able to import that but it's failing. Has that been changed recently? Is there a correct way to import this from the library?

@Atticuszz
Copy link

try import by from supabase.lib.client_options import ClientOptions?maybe work

@Atticuszz
Copy link

i think it's carelessness and checked there's no ClientOptions in Supabase.init.py,you can add a new PR to solve it,my computer is not aside with me

@silentworks silentworks added the bug Something isn't working label Feb 14, 2024
@silentworks silentworks added this to the Stable milestone Feb 14, 2024
@silentworks
Copy link
Contributor

silentworks commented Feb 15, 2024

This should now be available in the latest 2.3.5 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

3 participants