pyRethinkORM icon indicating copy to clipboard operation
pyRethinkORM copied to clipboard

RqlCompileError: Unrecognized optional argument `upsert`

Open ehmo opened this issue 11 years ago • 2 comments

Hey guys,

I started playing with RethinkDB today. Everything worked well until I started using ORM.

import rethinkdb as r
from rethinkORM import RethinkModel

r.connect( "localhost", 28015).repl()

class test(RethinkModel):
    table = "authors"

dhdProp = test(what="DHD", planet="P3X-439", description="Dial HomeDevice")
dhdProp.id="DHD_P3X_439"
dhdProp.save()

the result is

rethinkdb.errors.RqlCompileError: RqlCompileError: Unrecognized optional argument `upsert`. in:
r.table('authors').insert(r.expr({'planet': 'P3X-439', 'what': 'DHD', 'description': 'Dial HomeDevice', 'id': 'DHD_P3X_439'}), durability='soft', upsert=True)

Any idea what to do?

ehmo avatar Sep 16 '14 02:09 ehmo

Looks like the python driver was updated to replace upsert=True with conflict='replace' in 1.14. The requirements do specify 1.7, but it should probably be updated in line in both master and dev.

The change is simple for master (see below), I'll look at making sure it doesn't break tests and submit a PR as soon as I get a chance.

Reference: https://github.com/rethinkdb/rethinkdb/issues/1838

diff --git a/rethinkORM/rethinkModel.py b/rethinkORM/rethinkModel.py
index e39fb96..a4b2980 100644
--- a/rethinkORM/rethinkModel.py
+++ b/rethinkORM/rethinkModel.py
@@ -33,7 +33,7 @@ class RethinkModel(object):
     non_atomic = False
     """Determins if the transaction can be non atomic or not"""

-    upsert = True
+    conflict = 'replace'
     """Will either update, or create a new object if true and a primary key is
     given."""

@@ -261,7 +261,7 @@ name exists in data""")
             reply = r.table(self.table) \
                 .insert(self._data,
                         durability=self.durability,
-                        upsert=self.upsert) \
+                        conflict=self.conflict) \
                 .run(self._conn)
             self._new = False

grieve avatar Sep 16 '14 10:09 grieve

Thanks for looking into this so fast, @grieve. I don't believe I have any tests that are using or testing upsert (although I probably should) so just that change should be fine.

JoshAshby avatar Sep 16 '14 15:09 JoshAshby