Re: Do MappingStorage is able to solve conflicts
Éloi Rivard <[email protected]> Fri, 12 Oct 2018 08:46:21 -0700 (PDT)
| Newsgroups | gmane.comp.web.zope.zodb |
|---|---|
| Message-ID | <[email protected]> |
------=_Part_752_191166930.1539359181740 Content-Type: multipart/alternative; boundary="----=_Part_753_1206953298.1539359181740" ------=_Part_753_1206953298.1539359181740 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I did not know about DemoStorage, it seems to do the job. Thank you! Le vendredi 12 octobre 2018 17:03:08 UTC+2, Jason Madden a =C3=A9crit : > > MappingStorage does not extend ConflictResolvingStorage and I wouldn't=20 > expect it to resolve conflicts.=20 > > If you want an in-memory storage that does resolve conflicts, try=20 > DemoStorage (if not given a base or changes storage, it uses MappingStora= ge=20 > objects).=20 > > > On Oct 12, 2018, at 05:02, =C3=89loi Rivard <[email protected] <javascri= pt:>>=20 > wrote:=20 > >=20 > > Hi. I have a very simple piece of code with a different behavior=20 > depending on it is running on a MappingStorage or a ClientStorage.=20 > Conflicts do not seem to be solved when I use a MappingStorage.=20 > >=20 > > import ZODB, transaction, persistent=20 > > from ZEO.ClientStorage import ClientStorage=20 > >=20 > > class MyMapping(persistent.mapping.PersistentMapping):=20 > > def _p_resolveConflict(self, old, saved, new):=20 > > return {"conflict": "happened"}=20 > >=20 > >=20 > > db =3D ZODB.DB(None)=20 > > #db =3D ZODB.DB(ClientStorage(("localhost", 9999)))=20 > > with db.transaction() as conn:=20 > > conn.root.x =3D MyMapping()=20 > >=20 > > my_transaction_manager =3D transaction.TransactionManager()=20 > > conn1 =3D db.open(my_transaction_manager)=20 > > my_transaction_manager.commit()=20 > >=20 > > with db.transaction() as conn2:=20 > > conn2.root.x["a"] =3D 1=20 > >=20 > > conn1.root.x["b"] =3D 2=20 > > my_transaction_manager.commit()=20 > >=20 > > This piece of code is stupid, but just shows that a conflict is raised= =20 > with a MappingStorage, and not with a ClientStorage.=20 > >=20 > > =C3=89loi=20 > >=20 > > --=20 > > You received this message because you are subscribed to the Google=20 > Groups "zodb" group.=20 > > To unsubscribe from this group and stop receiving emails from it, send= =20 > an email to [email protected] <javascript:>.=20 > > For more options, visit https://groups.google.com/d/optout.=20 > > --=20 You received this message because you are subscribed to the Google Groups "= zodb" group. To unsubscribe from this group and stop receiving emails from it, send an e= mail to [email protected]. For more options, visit https://groups.google.com/d/optout. ------=_Part_753_1206953298.1539359181740 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div>I did not know about DemoStorage, it seems to do the = job.</div><div><br></div><div>Thank you!<br></div><br>Le vendredi 12 octobr= e 2018 17:03:08 UTC+2, Jason Madden a =C3=A9crit=C2=A0:<blockquote class=3D= "gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s= olid;padding-left: 1ex;">MappingStorage does not extend ConflictResolvingSt= orage and I wouldn't expect it to resolve conflicts. <br> <br>If you want an in-memory storage that does resolve conflicts, try DemoS= torage (if not given a base or changes storage, it uses MappingStorage obje= cts). <br> <br>> On Oct 12, 2018, at 05:02, =C3=89loi Rivard <<a href=3D"javascr= ipt:" target=3D"_blank" gdf-obfuscated-mailto=3D"eLp1ys2qBAAJ" rel=3D"nofol= low" onmousedown=3D"this.href=3D'javascript:';return true;" onclick= =3D"this.href=3D'javascript:';return true;">[email protected]</a>>= ; wrote: <br>>=20 <br>> Hi. I have a very simple piece of code with a different behavior d= epending on it is running on a MappingStorage or a ClientStorage. Conflicts= do not seem to be solved when I use a MappingStorage. <br>>=20 <br>> import ZODB, transaction, persistent <br>> from ZEO.ClientStorage import ClientStorage <br>>=20 <br>> class MyMapping(persistent.mapping.<wbr>PersistentMapping): <br>> =C2=A0 =C2=A0 def _p_resolveConflict(self, old, saved, new): <br>> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return {"conflict": "ha= ppened"} <br>>=20 <br>>=20 <br>> db =3D ZODB.DB(None) <br>> #db =3D ZODB.DB(ClientStorage(("<wbr>localhost", 9999))) <br>> with db.transaction() as conn: <br>> =C2=A0 =C2=A0 conn.root.x =3D MyMapping() <br>>=20 <br>> my_transaction_manager =3D transaction.<wbr>TransactionManager() <br>> conn1 =3D db.open(my_transaction_<wbr>manager) <br>> my_transaction_manager.commit(<wbr>) <br>>=20 <br>> with db.transaction() as conn2: <br>> =C2=A0 =C2=A0 conn2.root.x["a"] =3D 1 <br>>=20 <br>> conn1.root.x["b"] =3D 2 <br>> my_transaction_manager.commit(<wbr>) <br>>=20 <br>> This piece of code is stupid, but just shows that a conflict is ra= ised with a MappingStorage, and not with a ClientStorage. <br>>=20 <br>> =C3=89loi <br>>=20 <br>> --=20 <br>> You received this message because you are subscribed to the Google= Groups "zodb" group. <br>> To unsubscribe from this group and stop receiving emails from it, = send an email to <a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-m= ailto=3D"eLp1ys2qBAAJ" rel=3D"nofollow" onmousedown=3D"this.href=3D'jav= ascript:';return true;" onclick=3D"this.href=3D'javascript:';re= turn true;">zodb+uns...@googlegroups.<wbr>com</a>. <br>> For more options, visit <a href=3D"https://groups.google.com/d/opt= out" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D'htt= ps://groups.google.com/d/optout';return true;" onclick=3D"this.href=3D&= #39;https://groups.google.com/d/optout';return true;">https://groups.go= ogle.com/d/<wbr>optout</a>. <br> <br></blockquote></div> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups &= quot;zodb" group.<br /> To unsubscribe from this group and stop receiving emails from it, send an e= mail to <a href=3D"mailto:[email protected]">zodb+unsubscri= [email protected]</a>.<br /> For more options, visit <a href=3D"https://groups.google.com/d/optout">http= s://groups.google.com/d/optout</a>.<br /> ------=_Part_753_1206953298.1539359181740-- ------=_Part_752_191166930.1539359181740--