-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactor Part I: Deprecate & Rename Old Routes #64
Conversation
7b96972
to
4b34406
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.
thanks for this, this is in the right direction, I didn't aprove yet because I've found myself with some questions that I left in the PR.
response = self._get(route=route, raw=True) | ||
response.raise_for_status() | ||
return ExecutionResultCSV(data=BytesIO(response.content)) | ||
return self.get_execution_results_csv(job_id) | ||
|
||
def get_latest_result(self, query: Union[QueryBase, str, int]) -> ResultsResponse: |
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.
deprecate and replace w/ get_query_result()
?
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 is different than get_query_result
. Get latest, fetches the latest results buy query ID (as opposed to execution/job ID).
I suppose we could do as you suggest, but I personally find the two to be rather different.
cf:
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.
so I don't forget, I need to review this again, but we should have a get_query_result()
that uses a Query
and simply returns the latest available query result (using the API that exists for that).
This method has the clear difference that it doesnt use up any execution credits, which is important.
dune_client/client.py
Outdated
raise ImportError( | ||
"dependency failure, pandas is required but missing" | ||
) from exc | ||
data = self.refresh_csv(query, performance=performance).data |
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 other way around, make refresh_csv()
use this function instead.
also, what do you think about changing the ordering of the methods in the class?
shall we move:
- old deprecated functions go AFTER the new official ones
- internal helper methods or functions go to the end of the file (or to a separate helper class altogether?)
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 other way around, make refresh_csv() use this function instead.
Yes, this was just overlooked, will fix.
-
I was saving the reordering for the larger refactor (when we split the class into multiple subclasses). This is already proposed in PR Refactor Part II: Split DuneClient Class #72 (where the deprecated functions have been moved to the bottom of their respective new locations).
-
Also, internal helper methods have been moved (in Refactor Part II: Split DuneClient Class #72) to a class called
ExtendedAPI
(naming can easily be changed upon request).
@@ -148,7 +148,7 @@ def test_internal_error(self): | |||
query.query_id = 9999999999999 | |||
|
|||
with self.assertRaises(DuneError) as err: | |||
dune.execute(query) | |||
dune.execute_query(query) |
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.
Now, looking at the code and having refreshed my memory:
question for you:
- if we have a
QueryBase
orQuery
object, shouldn't we have the methods on that class: - query.execute()
- query.result()
- etc.. ?
with functions like dune.execute_query()
it feels more idiomatic this way:
res = dune.execute_query(query_id=1234)
instead of:
res = dune.execute_query(Query(1234))
for me, the two idiomatic options would be:
- dune.execute_query(1234) # or query_id=1234
- dune.Query(1234).execute()
Right now, I see bits of OO in here, but inconsistently:
- Executions are simply
job_id
- Queries are objects, with a query_id inside (it should be Query.id, right?)
- but we don't have methods on Queries..
- if we did, it would add structure to expand the library for varying types of APIs and do a cleaner split between concepts.
this is just food for thought, the goal here is to improve the code for readability and dev experience in a simple, pragmatic way.
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.
I definitely agree some things like this could be approached differently. In all of the ways suggested above. These things have been on my mind for quite some time. I believe the reason we went for query_id
is that some of these low level methods are never actually used by the end user and none of the additional query attributes are used. Most consumers of the client are usually calling refresh.
Maybe it can be made compatible with multiple approaches (i.e. introduce some method overrides where users can pass Query object or query_id
). I would have to think a bit further if we can extend the functionality to the Query object itself in a backwards compatible way, but I would be wiling to give it a try.
202f26d
to
6bc5f80
Compare
I hope some of the questions are now answered (or in some cases at least postponed to the next PR). |
10b15a0
to
c21da35
Compare
the functions touched here are:
Maybe a couple others I forgot.
We had to temporarily add a pylint: ignore
too-many-public-methods
but this will be lifted when we split the client intoDuneExecutionsAPI, DuneQueryAPI, DuneUploadAP
- See #72cc @TheEdgeOfRage & @diegoximenes for additional review.