-
Notifications
You must be signed in to change notification settings - Fork 458
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
Make original list object accessible on iterators #1148
Conversation
2625cae
to
75337fa
Compare
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.
The changes look good, thanks for doing the work. I think I prefer this approach because it feels more future proof as you just track the "last response" for the most recent request instead of at an object level. At least it seems to solve the original issue more specifically than setting it on a per object in the page.
The code is fairly specific though in parts of the library I don't know really well so we should get @ob-stripe and @richardm-stripe to look too.
I flagged what I think might be a breaking change. Could you also add some tests to cover this behavior?
75337fa
to
fc6cc5b
Compare
Thanks Remi.
Yeah, it's actually the change to
I added a basic test around the accessors on @ob-stripe / @richardm-stripe Definitely feel free to take a look as well. I'll push up the rest of the changes with all the other |
@@ -9,23 +9,23 @@ import ( | |||
) | |||
|
|||
func TestIterEmpty(t *testing.T) { | |||
tq := testQuery{{nil, ListMeta{}, nil}} | |||
tq := testQuery{{nil, &ListMeta{}, nil}} |
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.
These all changes so that I can have testQuery
take a ListContainer
instead of ListMeta
. ListContainer
is an interface, so it requires a pointer.
dd9028c
to
a2c23ad
Compare
Alright, open for a final round of feedback on this one everyone! Core code hasn't changed, but I've now modified |
And did one final round of adding tests for all new accessors to get our coverage back up (which also caught a couple errors, phew). |
This patch makes some tweaks to `Iter` so that it doesn't just retain list metadata, but a reference to the entirety of the list object. This is mainly useful so that it'd be possible to access the last API response, which could be used for things like this: ``` go requestID := it.CustomerList().LastResponse.RequestID ``` Currently, it's not possible to access a list operation's last response because we only set `LastResponse` on the top level API resource (which is the list in this case), and `Iter` provides no access to that. I also introduce a new `ListContainer` interface that all lists inherit through their embedded `ListMeta` just to convey more typing information so that we don't have to use an untyped `interface{}`. I think this is fine though because it's very nicely symmetric with what we already have for `ListParamsContainer` which has a nearly identical implementation. The downside is that this changes the definition of `Query`: ``` go // Old definition type Query func(*Params, *form.Values) ([]interface{}, ListMeta, error) // New definition type Query func(*Params, *form.Values) ([]interface{}, ListContainer, error) ``` This is technically a breaking change because `Query` is exported from the `stripe` package, but it's one of those changes that's very unlikely to affect that vast majority of users because it's not a type that you'd ever be using most of the time. We also have to make a slight change to every existing `List` function to adopt the new `Query` signature. I've shown what this would look like in the changes in `customer/client.go`. Unfortunately, I can't find many solutions to getting access to `LastResponse` that _don't_ involve changing every `List` implementation to some degree. Similarly, we also add a new function to every resource's `Iter` like `CustomerList` to get back a typed version of the list object, similar to how each already has a function to get a typed version of its API resource like `Customer()`. Fixes #1141.
e755eeb
to
6733be9
Compare
Just rebased and added the updates to I talked this over with Remi, and although there is technically a breaking change here to an exported type ( |
Released as 71.44.0. |
This patch makes some tweaks to
Iter
so that it doesn't just retainlist metadata, but a reference to the entirety of the list object.
This is mainly useful so that it'd be possible to access the last API
response, which could be used for things like this:
Currently, it's not possible to access a list operation's last response
because we only set
LastResponse
on the top level API resource (whichis the list in this case), and
Iter
provides no access to that.I also introduce a new
ListContainer
interface that all lists inheritthrough their embedded
ListMeta
just to convey more typing informationso that we don't have to use an untyped
interface{}
. I think this isfine though because it's very nicely symmetric with what we already have
for
ListParamsContainer
which has a nearly identical implementation.The downside is that this changes the definition of
Query
:This is technically a breaking change because
Query
is exported fromthe
stripe
package, but it's one of those changes that's very unlikelyto affect that vast majority of users because it's not a type that you'd
ever be using most of the time.
We also have to make a slight change to every existing
List
functionto adopt the new
Query
signature. I've shown what this would look likein the changes in
customer/client.go
. Unfortunately, I can't find manysolutions to getting access to
LastResponse
that don't involvechanging every
List
implementation to some degree. Similarly, we alsoadd a new function to every resource's
Iter
likeCustomerList
to getback a typed version of the list object, similar to how each already has
a function to get a typed version of its API resource like
Customer()
.Fixes #1141.
r? @remi-stripe Can you take a perfunctory initial review for this one?
Also see my last comment in #1141.