Ax icon indicating copy to clipboard operation
Ax copied to clipboard

Generation strategy is not associated with correct experiment when using SQL storage after JSON deserialization

Open alxfed opened this issue 4 years ago • 3 comments

In particular: If you archive or store a generation strategy as json, then ingest it back and transform into an object with the help of generation_strategy_from_json() function the attached _experiment has db_id = None. Then, if you try to save it to the SQA store with the help of save_generation_strategy() (after saving the corresponding experiment first of course) the _save_generation_strategy() function is allegedly checking whether the experiment exists and already is in the database (lines 115 - 126 in save.py module), but that's not what happens. It verifies whether the _experiment attached to the recovered generation strategy object has a db_id (which is always None there in this scenario). Of course the workaround is to read the db_id of the experiment from the database, then assign this db_id directly by gs.experiment.db_id = the_existing_db_id then save the modified generation strategy object... but I have a feeling that it would be better if you did it yourself starting from the line 115 and on of the sqa_store/save.py module.

alxfed avatar Dec 29 '21 17:12 alxfed

We'll investigate this and get back to you @alxfed! In the meantime, this workaround should help:

recovered_exp = experiment_from_json(...)
recovered_gs = generation_strategy_from_json(...)
recovered_gs._experiment = recovered_exp
save_generation_strategy(recovered_gs)

Let me know if that doesn't fix!

lena-kashtelyan avatar Jan 05 '22 16:01 lena-kashtelyan

As I said: I first save the recovered experiment, then take the db_id from it (this saved experiment) and 'by hand' assign it recovered_gs.experiment.db_id = saved_recovered_experiment.db_id , then save the resulting gs. And it works fine. I'm just worrying about the unsuspecting newcomers who will read the docstring and nothing else. Sorry for bothering you with this.

alxfed avatar Jan 06 '22 01:01 alxfed

@alxfed, yep that makes sense, was just suggesting a workaround that doesn't manually mess with the db_id attribute : )

lena-kashtelyan avatar Jan 06 '22 16:01 lena-kashtelyan

This is fixed now, provided generation_strategy_from_json is used correctly (with the restored experiment object passed to it as input.

lena-kashtelyan avatar Sep 13 '22 17:09 lena-kashtelyan