-
Notifications
You must be signed in to change notification settings - Fork 6
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
Introduce run.clone()
#141
base: enh/run-get-by-id
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## enh/run-get-by-id #141 +/- ##
=================================================
Coverage 87.0% 87.1%
=================================================
Files 230 231 +1
Lines 8170 8216 +46
=================================================
+ Hits 7113 7160 +47
+ Misses 1057 1056 -1
|
2e9cb4c
to
8513cac
Compare
73b59c6
to
0975ce3
Compare
I would not add an endpoint for this, especially as it does not actually add any functionality (by definition a run that is cloned could already be created via the REST API) and I hope that we wont be cloning thousands of runs on a regular basis. |
Just to clarify: Ill accept the PR also with the current idea, just still reading through it... |
Two quick responses to @meksor:
The benefit of a dedicated endpoint would be that the data would be copied within/close to the database, right? Avoiding that the data is sent back and forth via the RestAPI. Also, having a dedicated
Sorry, cloning runs happens all the time in MESSAGE modelling - every time a user does a variation of an existing scenario, you start by cloning the base scenario and make some modifications. |
OK, convinced! |
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.
Hi, as said, i think the two tests added here could benefit from comments/whitespace/abstraction to make them easier to read.
A hard requirement is a test that checks if clone
respects the permission check!
(It looks like it does since it uses create
, but its best to bake this into a test.)
You can add a test in test_auth.py
Thanks for your review :) As for the readability: I tried adding some blank lines and comments, but I'm actually just adding one test here (not counting the auth test, which does not require the same setup), so I'm not sure how to abstract things away here short of a refactoring regarding how we call the methods of adding data to optimization items or listing them. Please let me know what you think. |
tests/test_auth.py
Outdated
assert_cloned_run(run, clone_with_solution, kept_solution=True) | ||
else: | ||
with pytest.raises(Forbidden): | ||
_ = run.clone() |
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.
You should be able to just add to the test_filters
and test_guards
tests above
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.
Ah, that should be done now :)
8c584c2
to
d69ff7c
Compare
Closes #133 :)
This is the next part of cleaning up #101, but it also improves the code that was originally introduced there, though I'm not entirely happy with all changes.
The goal was to enable
run.clone()
in the core layer. For that,clone()
had to move outside of the coreRunRepository
sinceRun
is not related to that. The most logical place to put it seemedbackend.runs.clone()
to me, so I did that, but it also warrants addingclone()
to the REST API.With
clone()
, we're creating a newrun
, which sounds like aPOST
request to me. However, we already intercept all those requests to/runs/
, so I had to find a new way. Rather than going for another request method, I opted to redirect allPOST
requests to/runs/clone/
, which is not otherwise in use, toclone()
in the DB layer. Please let me know if this is appropriate.The actual logic for
clone()
worked well in the core layer, where it could make use of therun.iamc
object encapsulating some validation and formatting operations. I tried to move these helper functions to the DB layer, but some require access to a specificrun
, making them unsuitable to be used in the DBRunRepository
. Thus, I duplicated their logic within theclone()
function, which is likely not the best solution. Please let me know which alternative we can employ.Lastly, I found two oddities referring to type hints, both marked as
TODO
inline:core.indexset.data
returns alist[float] | list[int] | list[str]
now, which is technically correct: there can only be one type in anyindexset.data
list. However, type checkers then don't know if they should allow something likeindexset.add("foo")
since they can't guarantee that.data
is alist[str]
this time. I'm not sure how, but it would be great to annotate.data
... dynamically I guess, so that it's recognized correctly and specifically.iamc
functions likeiamc.datapoints.bulk_upsert()
are annotated inconsistently. In the abstract layer, they may proclaim to accept apd.DataFrame
, whereas in the DB layer, they require apandera.DataFrame
of a specific schema. This leads to sometype: ignore
that we could probably remove, but I'm not sure how we would want to do that.We could of course adapt the type hint to accept both kinds of dataframes, but we probably want to ensure that the data are validated even when the DB layer is called directly, so we probably don't want to let simple
pd.DataFrames
slip. Just usingpandera.DataFrame
s might be tricky, too, as e.g.pandera.DataFrame["run__id"]
tells me I can't index apandera.DataFrame
. I'm happy to hear suggestions here :)