volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

Upsert with updateOnConflict=false incorrectly requires updateColumns #418

Closed pennersr closed 5 years ago

pennersr commented 5 years ago

If you're having a generation problem please answer these questions before submitting your issue. Thanks!

What version of SQLBoiler are you using (sqlboiler --version)?

v3.1.0

Further information. What did you do, what did you expect?

The generated Upsert has the following signature:

func (o *SomeModel) Upsert(ctx context.Context, exec boil.ContextExecutor, updateOnConflict bool, conflictColumns []string, updateColumns, insertColumns boil.Columns) error

Its implementation body contains this line:

        if len(update) == 0 {
            return errors.New("models: unable to upsert somemodel, could not build update column list")
        }

I was invoking this method passing updateOnConflict=false. Given that I do not want any updates, I am passing updateColumns=boil.Whitelist() -- the empty list.

Expected result: this works fine, I am not updating anything after all.

Actual result: the if pasted above causes an error.

aarondl commented 5 years ago

Adjusted that error so that it only occurs if people are attempting to update something. It's on the dev branch. Thanks for the bug report.