blaze / blaze/odo

Ability to overwrite/raise exception if target data already exists

Open
#288 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1k
Forks
131
PR merge metrics
No merged PRs in 30d

Description

For external data I'm writing with odo, I'd like the ability to overwrite the destination data or raise an exception if the target already exists, rather than simply appending to it. For context, I'm developing a tool that uses odo to convert and transfer data from one format or server to another, as an end-user service that can be invoked via Python or a Flask frontend.

As an example, let's say I have an odo call to convert an arbitrary object to `abc.csv`. At the moment, if the file already exists, my odo call will append new data onto whatever's already there. If I don't care about the contents of any file that may already exist, I'd like to just overwrite it. This also makes odo more idempotent, so that if the same function call is made twice, the same data would result.

On the other hand, if I could have important data in `abc.csv`, I may want to raise an exception if the target already exists to avoid destroying or modifying data, letting me either rename the file, delete it, or choose a different destination filename.

At the moment, I'd have to do something like this if I want to implement this functionality:

```
if_exists = # overwrite, raise, or append

if target_already_exists():
if if_exists == 'overwrite':
drop(target)
elif if_exists == 'raise'
raise SomeKindOfException

odo(source, target)
```

We discussed a few potential solutions on Gitter today:
- Create a new metatype that would allow you to overwrite data like `odo(source, overwrite(target))`. Odo would raise `NotImplementedError` for any types that didn't have `overwrite` variants defined.
- Some kind of `if_exists` keyword argument to odo that specifies the `append` behavior required that would have to be implemented by backends that support that functionality.
- A context manager that would allow you to specify an overwrite/raise option when invoking odo.

In the absence of a solution in odo to do this, an `exists` function similar to `drop` would help me implement the solution above, by providing a single function to check for the existence of objects rather than having to implement them all individually.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.