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

Client functions in v6.0.0 do not work - HTTP Client Object has no attribute insert_permission #1385

Closed
Joangaes opened this issue Jan 29, 2024 · 5 comments · Fixed by #1392
Assignees
Labels
Bug in progress Issue currently in progress by the assignee
Milestone

Comments

@Joangaes
Copy link

Joangaes commented Jan 29, 2024

Important: Please do not post usage questions here.
To get a quick response, please ask a question on Stack Overflow using gspread tag.
See existing questions: https://stackoverflow.com/questions/tagged/gspread


Describe the bug
When we are sharing a spreadsheet there is an issue with Sharing since the HTTPClient doesn't have the insert_permission function.

To Reproduce
Steps to reproduce the behavior:

  1. Create a Spreadsheet
  2. Use the share function.

Expected behavior
We should be able to share stuff.

@teodororo
Copy link

@Joangaes, sorry for taking advantage of your issue, but I had a similar problem so I'll just add it here. It was with the export function.

Traceback (most recent call last):
  File "xxx.py", line xxx, in <module>
    export_file = workbook.export(format=ExportFormat.EXCEL)
  File "/home/xxx/oss/changehistory/venv/lib/python3.8/site-packages/gspread/spreadsheet.py", line 518, in export
    return self.client.export(self.id, format)
AttributeError: 'HTTPClient' object has no attribute 'export'

Here's what I've tried:

import gspread
gc = gspread.service_account()
sh = gc.open("XXX").export()

@alifeee
Copy link
Collaborator

alifeee commented Jan 29, 2024

Hi, thanks for the issue :)

This seems to be a big problem with the new release. For now I would consider using the latest version v5.12.4 until this is fixed, with

pip install gspread==5.12.4

Information

I am not sure what the problem is, but I provide relevant parts of code for v5 and v6

v5 (old, working)

class Client:
    def __init__(self, auth, session=None):
        if auth is not None:
            self.auth = convert_credentials(auth)
            self.session = session or AuthorizedSession(self.auth)
        else:
            self.session = session
        self.timeout = None
    def open(self, title, folder_id=None):
        spreadsheet_files, response = self._list_spreadsheet_files(title, folder_id)
        try:
            properties = finditem(
                lambda x: x["name"] == title,
                spreadsheet_files,
            )
        except StopIteration as ex:
            raise SpreadsheetNotFound(response) from ex
        # Drive uses different terminology
        properties["title"] = properties["name"]
        return Spreadsheet(self, properties)
class Spreadsheet:
    def __init__(self, client, properties):
        self.client = client
    ...
    def export(self, format=ExportFormat.PDF):
        return self.client.export(self.id, format)

v6 (new, broken)

class Client:
    def __init__(
        self, auth: Credentials, http_client: HTTPClientType = HTTPClient
    ) -> None:
        self.http_client = http_client(auth)
    def open(self, title: str, folder_id: Optional[str] = None) -> Spreadsheet:
        spreadsheet_files, response = self._list_spreadsheet_files(title, folder_id)
        try:
            properties = finditem(
                lambda x: x["name"] == title,
                spreadsheet_files,
            )
        except StopIteration as ex:
            raise SpreadsheetNotFound(response) from ex
        # Drive uses different terminology
        properties["title"] = properties["name"]
        return Spreadsheet(self.http_client, properties)
class Spreadsheet:
    def __init__(self, http_client, properties):
        self.client = http_client
    ...
    def export(self, format=ExportFormat.PDF):
        return self.client.export(self.id, format)

I must go now but the investigation can be continued from here. Looks like a problem with what is passed to the Spreadsheet initialisation, as one passes an entire Client object, and the other just the http_client, which does not have the export method attached to it.

@lavigne958 lavigne958 added this to the 6.0.1 milestone Jan 29, 2024
@alifeee alifeee pinned this issue Jan 29, 2024
@alifeee alifeee changed the title GSpread HTTP Client Object has no attribute insert_permission Client functions in v6.0.0 do not work - HTTP Client Object has no attribute insert_permission Jan 29, 2024
@alifeee
Copy link
Collaborator

alifeee commented Jan 29, 2024

@lavigne958 you assign me but I do not know much about the Client object, perhaps it is better if you take a look as you know more about it and the changes that were made v5->v6?

@lavigne958
Copy link
Collaborator

I saw your first investigation I thought you wanted to continue when you have time.
I understand, I'll have a look then.

I think we can provide a fix for both issues that just raised and then release 6.0.1 with both fixes, you agree ?

@lavigne958 lavigne958 assigned lavigne958 and unassigned alifeee Jan 29, 2024
@lavigne958
Copy link
Collaborator

I went through the list of missing actions it seems the new HTTP client is missing the bellow actions:

  • export
  • list_permissions
  • insert_permission/share
  • remove_permission

I will fix that soon (in a couple of days at most) and make the next fixup release 6.0.1

thank you everyone for helping.

programmist003 added a commit to programmist003/vk-ads-analytics that referenced this issue Jan 29, 2024
@lavigne958 lavigne958 added Bug in progress Issue currently in progress by the assignee labels Jan 30, 2024
lavigne958 added a commit that referenced this issue Jan 30, 2024
The `HTTPClient` class was missing the `export` method.

Add it in order for the gspread `Client` and the
`Spreadsheet` class to use it to export spreadsheets.

closes #1385

Signed-off-by: Alexandre Lavigne <[email protected]>
lavigne958 added a commit that referenced this issue Jan 30, 2024
Add missing methods to the HTTP client.

update code so the gspread Client and the spreadsheet use
these new methods in order to:
- insert
- list
- remove

a permission.

We can't test these function automatically as this requires
exposing personal information in the recorded requests.

We'll add more tests later when we find a way.

closes #1385

Signed-off-by: Alexandre Lavigne <[email protected]>
@lavigne958 lavigne958 unpinned this issue Feb 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug in progress Issue currently in progress by the assignee
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants