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

worksheet.add_protected_range() - impossible to create the warning_only=True range #1437

Closed
aperepel opened this issue Mar 13, 2024 · 2 comments · Fixed by #1439
Closed

worksheet.add_protected_range() - impossible to create the warning_only=True range #1437

aperepel opened this issue Mar 13, 2024 · 2 comments · Fixed by #1439

Comments

@aperepel
Copy link

Hi, I wonder if there's a bug.

When using worksheet.add_protected_range(name="A1:B2", warning_only=True), I'm getting the TypeError: Worksheet.add_protected_range() missing 1 required positional argument: 'editor_users_emails'

However, adding editor_users_emails triggers a 400 Bad Request, as the library seems to always require it:

worksheet.add_protected_range(name="A1:B2", warning_only=True, editor_users_emails="[email protected]")

--- (and the error is)

ProtectedRange is warningOnly. Editors cannot be set on it.

I think the gspread library must omit the editor node altogether from the request if warning_only=True.

@aperepel
Copy link
Author

FYI, I had to fallback to the raw API, here's what the working request looks like:

grid_range = gspread_utils.a1_range_to_grid_range(cell_range)

    request_body = {
        "requests": [
          {
              "addProtectedRange": {
                  "protectedRange": {
                      "range": {
                          "sheetId": int(worksheet_id),
                          "startRowIndex": grid_range['startRowIndex'],
                          "endRowIndex": grid_range['endRowIndex'],
                          "startColumnIndex": grid_range['startColumnIndex'],
                          "endColumnIndex": grid_range['endColumnIndex'],
                      },
                      "warningOnly": True
                  }
              }
          }
       ]
    }

    res = gsheet.batch_update(request_body)

@alifeee
Copy link
Collaborator

alifeee commented Mar 15, 2024

Hi, thanks for this issue. You have made it very clear the problem, which is great.

I have made a fix with #1439. If no problems arise, it should appear in the next minor release :)

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 a pull request may close this issue.

2 participants