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
Fix missing attribute spreadsheet
in Worksheet
.
#1402
Conversation
The `Worksheet` object was missing the `spreadsheet` attribute. Add it back to be backward compatible. closes #1395 Signed-off-by: Alexandre Lavigne <lavigne958@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good.
it is worrying that we do not have to change any tests for this behaviour.
Perhaps we should add one?
Add a new test to ensure the public attributes of a `Worksheet` object don't change. make the `spreadsheet` attribute private and create a property to keep its public access. This will allow us to add deprecation warnings later *if* we deprecate it. Signed-off-by: Alexandre Lavigne <lavigne958@gmail.com>
you're right, I added a safeGuard test to keep access to public attributes and check their types too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job with the recursive type-checking! :)
looking at this made me think of something. In v5 -> v6, the Worksheet
constructor is changed
class Worksheet
def __init__(
self,
- spreadsheet,
+ spreadsheet_id: str,
+ client: HTTPClient,
properties
):
This is a breaking change. It should be documented in the migration guide, as people now have to construct Worksheets differently.
Alternatively, this PR reintroduces the spreadsheet
argument to Worksheet.__init__()
, so we could try to make the __init__
signature the same as in v5, so it is not a breaking change.
This would probably look something like
class Worksheet
def __init__(
self,
spreadsheet,
properties,
+ client: HTTPClient = None,
):
+ self.spreadsheet_id = spreadsheet.id
+ if client is None:
+ # raise warning/throw error/make client HTTPClient
Then people could still use gspread.Worksheet(spreadsheet, properties)
as in v5.
What do you think?
Thanks 🙏
This should not be a problem as the only way to obtain a worksheet is through the spreadsheet object (using like That's how the project is designed at least, but you never know what users could do with it. Then we must raise an error like you propose if someone tried to instantiate it with no client, so even if we keep the same constructor signature their code will raise some error anyway so they'll need to passe the HTTP client anyway. I understand the issue, though to me it's not an expected use case by gspread. |
This may be the most common way, but the Worksheet object is publicly accessible, no? Any user can use it like, import Worksheet from gspread.Worksheet
...
my_custom_worksheet = Worksheet(...) So changing the initialisor signature would break this.
you can never expect users to only do as expected ;) So maybe we make the breaking change still, but put it in the migration guide? |
You're right, I will upgrade it so the signature matches + the new extra argument (the HTTP Client) We need to raise in case the HTTP Client is not given at least users will have an explicit error message here. Can you add it to the |
Updated the signature of `Worksheet.__init__` method in order to be backward compatible. Users are not meant to use but just in case someone does. It will properly raise an error with explicit message. Signed-off-by: Alexandre Lavigne <lavigne958@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks good I will write the migration guide very soon :)
The
Worksheet
object was missing thespreadsheet
attribute.Add it back to be backward compatible.
closes #1395
Signed-off-by: Alexandre Lavigne lavigne958@gmail.com