Re: INSERT and .refresh() problems
Jacob Smullyan <[email protected]> Sun, 26 Jun 2005 22:03:06 -0400
| Newsgroups | gmane.comp.web.skunkweb |
|---|---|
| Message-ID | <[email protected]> |
On Mon, Jun 27, 2005 at 03:20:02AM +0200, Faber wrote:
> In previous version of PyDO2 that would work, but in the latest I receive
> following exception on a.refresh() call:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "pydo/base.py", line 626, in refresh
> raise ValueError, "current object doesn't exist in database!"
> ValueError: current object doesn't exist in database!
>
> Should I do a Relation.commit() before the a.refresh() call or it's a bug
> and I can continue to use this code, waiting for the fix? ;)
I'm trying to reproduce this bug, but so far, it I'm not able to
(using the svn head, which I don't think is different from the beta in
this respect). I just checked in a test case to tests/test_base.py,
which you can test there if you are able to follow along in
subversion, that tries to do what you are doing:
class test_refresh2(base_fixture):
usetables=('A', 'B')
tags=alltags
def pre(self):
self.B.new(x=4)
def run(self):
obj=self.B.getUnique(id=1)
obj.refresh()
assert obj.id==1
assert obj.x==4
n=self.A.new(name='ho hum',
b_id=obj.id,
ta=0,
x=0,
y=0,
z=0)
assert n.id==1
The foreign key relationship is actually irrelevant, since presumably
you are getting the failure at the refresh itself. But I'm not; this
test passes for me. I'm also using psycopg:
$ python -c 'import psycopg;print psycopg.__version__'
2.0b3 (dt ext pq3)
So your failure is probably still a PyDO bug, but not the one I'm
testing for -- or our environments are behaving differently. If this
test works for you but you still have an application error, could you
try turning into a test case? (Naked unittest greed.)
One other thing, btw -- you do not need to refresh to get an
autoincrement or sequence value. With sequences, PyDO fetches the
sequence first and explicitly inserts it; with autoincrement, the
autoincrement value is found during the new operation. If this were
not the case, refresh would be impossible when the unique constraint
is a sequence/autoincrement field.
Cheers,
js
--
Jacob Smullyan
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) iD8DBQFCv15auqamFyFXXLIRAm9GAJ9a77wVwKEdc05JMBFZS6nSWOeTzwCgyCUQ RS5VILeY2gA/aJN5xaSjesA= =l6Ub -----END PGP SIGNATURE-----