Closed jreyesr closed 3 years ago
Required changes:
core/utils
create_rgb_tiff
on https://github.com/IS-AgroSmart/AgroSmart-Web/blob/b8e38c7e90738ffa7b96edb7a480f340dd28f9d0/core/models.py#L270create_index_raster
on https://github.com/IS-AgroSmart/AgroSmart-Web/blob/b8e38c7e90738ffa7b96edb7a480f340dd28f9d0/core/models.py#L363_get_git_info
on https://github.com/IS-AgroSmart/AgroSmart-Web/blob/b8e38c7e90738ffa7b96edb7a480f340dd28f9d0/prometheus_metrics/views.py#L12upload_vectorfile
on https://github.com/IS-AgroSmart/AgroSmart-Web/blob/b8e38c7e90738ffa7b96edb7a480f340dd28f9d0/core/views.py#L395os.system
on one of the above functions to throw an exception, catch it on the test, assert that the current working dir is the original one nonetheless.
Some operations change the working dir of the Python server, to ease the execution of
os.system
calls. For an example, see below:https://github.com/IS-AgroSmart/AgroSmart-Web/blob/bef44a9357d1f3adea7ae067489fad11dd3548df/core/models.py#L270-L282
This means that, if an exception is thrown between the two calls to
os.chdir
(most likely on theos.system
call), the script will be left on that temporary directory. This is an inconsistent state, since parts of the code assume the current directory to beROOT_DIR/app
, whereROOT_DIR
is the directory where AgroSmart-Top was cloned. An example of this type of code would be the code that serves Flight thumbnails:https://github.com/IS-AgroSmart/AgroSmart-Web/blob/b8e38c7e90738ffa7b96edb7a480f340dd28f9d0/core/views.py#L354-L355
Proposed solution: implement a context manager to automatically restore the current working dir, even if the wrapped code raises an exception.