In preparation for doing a bulk insert into my app's tables I have been 
doing some testing from the web2py shell.

I issued the following command:

>>db.person.insert(name = 'Dustin Hoffman')

person.name has a unique=true setting as well as an IS_NOT_IN_DB form 
constraint. Dustin Hoffman is already in the database. 

The response for running this command was an id number (118)  suggesting 
the record had been added. However, when I looked at the person records via 
/myapplication/appadmin, it wasn't there and the id of the last record was 
117. This is fine, suggesting that the uniqueness constraint had been 
applied.

However, when I went back to the shell and issued this command -

>> db.person(118) 

- It returned a row.  Also

>> db.person(name='Dustin Hoffman').count
>> 2

So it seems as if the duplicate record is in the db, though it doesn't show 
up in the browser.

Two questions, then:

1. Why is the duplicate record not showing up in /myapplication/appadmin
2. If I want a script where duplicates are just rejected without special 
handling, should I just use insert_and_validate? What if I am doing a bulk 
insert or a csv import? 

-- 



Reply via email to