Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
duplicate records not throwing an exception
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Carl  
View profile  
 More options Apr 30, 1:07 pm
From: Carl <carl.ro...@gmail.com>
Date: Thu, 30 Apr 2009 10:07:57 -0700 (PDT)
Local: Thurs, Apr 30 2009 1:07 pm
Subject: duplicate records not throwing an exception
I have this in my model: db.py:

db.define_table('user',
                SQLField('email', 'string', length=320),
                SQLField('hash','string'))
db.user.email.requires=[IS_NOT_EMPTY(),IS_LOWER(),IS_NOT_IN_DB(db,
db.user.email)]

In my controller: default.py:

try:
uid = db.user.insert(email=request.vars.email,
                                   hash=converted)
except:
   etc...

I can execute the controller code again and again with the same value
in request.vars.email with success. I was expecting an exception to be
throw (which I would catch) when I tried to insert an existing email
address.

What am I missing?

Can anyone help?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdipierro  
View profile  
 More options Apr 30, 1:45 pm
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Thu, 30 Apr 2009 10:45:44 -0700 (PDT)
Local: Thurs, Apr 30 2009 1:45 pm
Subject: Re: duplicate records not throwing an exception
This

db.user.email.requires=[IS_NOT_EMPTY(),IS_LOWER(),IS_NOT_IN_DB
(db,db.user.email)]

is only enforced at the level for form validation. If you want the
database to enforce integrity

db.define_table('user',

>                 SQLField('email', 'string', length=320, unique=True),
>                 SQLField('hash','string'))

On Apr 30, 12:07 pm, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl  
View profile  
 More options Apr 30, 2:17 pm
From: Carl <carl.ro...@gmail.com>
Date: Thu, 30 Apr 2009 11:17:22 -0700 (PDT)
Local: Thurs, Apr 30 2009 2:17 pm
Subject: Re: duplicate records not throwing an exception
thanks M / very speedy concise reply.
p 138/139 explains it all - sorry to have missed this detail.

On Apr 30, 6:45 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl  
View profile  
 More options May 1, 6:06 am
From: Carl <carl.ro...@gmail.com>
Date: Fri, 1 May 2009 03:06:46 -0700 (PDT)
Local: Fri, May 1 2009 6:06 am
Subject: Re: duplicate records not throwing an exception
db.user.insert isn't throwing an exception if a duplicate record is
inserted but instead continues to the db.commit() instruction -- when
I using appadmin I can confirm that the duplicate record has been
added.

My insert code...

try:
   existingEmail = db.user.insert(email=request.vars.email,
                                           greet=False)
   db.commit()
except:
   #email record already exists
   ### handling code

Curiously... if I go to:
.../appadmin/select/db?query=db.user.id>0 then try to add a record
with a duplicate email address the form reports "value already in
database!"

This suggests that my db.py setting is okay. What am I missing in my
code?

Carl

On Apr 30, 7:17 pm, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdipierro  
View profile  
 More options May 1, 9:13 am
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Fri, 1 May 2009 06:13:03 -0700 (PDT)
Local: Fri, May 1 2009 9:13 am
Subject: Re: duplicate records not throwing an exception
what's the model? is unique=True in there?

On 1 Mag, 05:06, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl  
View profile  
 More options May 1, 9:17 am
From: Carl <carl.ro...@gmail.com>
Date: Fri, 1 May 2009 06:17:21 -0700 (PDT)
Local: Fri, May 1 2009 9:17 am
Subject: Re: duplicate records not throwing an exception
yes; it's:

db.define_table('user',
                SQLField('email', 'string', length=320, notnull=True,
required=True, unique=True),
                SQLField('greet', 'boolean'),
                SQLField('day', 'string', length=2),
                SQLField('month', 'string', length=9),
                SQLField('year', 'string', length=4))

and then for FORMs I have:
db.user.email.requires=[IS_LOWER(), IS_EMAIL(), IS_NOT_IN_DB(db,
db.user.email)]
db.user.greet.requires=[IS_NOT_EMPTY()]

I can't find in the web2py framework code where the exception would be
thrown.
I'm using sqlite locally.

On May 1, 2:13 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdipierro  
View profile  
 More options May 1, 9:29 am
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Fri, 1 May 2009 06:29:49 -0700 (PDT)
Local: Fri, May 1 2009 9:29 am
Subject: Re: duplicate records not throwing an exception
The database should throw and OperationalError at insert. Look into
sql.log and you should find the "CREATE TABLE... EMAIL UNIQUE..." I do
not know why sqlite is ignoring it.

Massimo

On 1 Mag, 08:17, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl  
View profile  
 More options May 1, 10:35 am
From: Carl <carl.ro...@gmail.com>
Date: Fri, 1 May 2009 07:35:35 -0700 (PDT)
Local: Fri, May 1 2009 10:35 am
Subject: Re: duplicate records not throwing an exception
ah! sqlite had become confused such that adding 'unique=True' to my
table definition didn't update the data store.
Deleting the data store and starting again has the behaviour sorted.

thanks for your feedback.

On May 1, 2:29 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdipierro  
View profile  
 More options May 1, 10:46 am
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Fri, 1 May 2009 07:46:02 -0700 (PDT)
Local: Fri, May 1 2009 10:46 am
Subject: Re: duplicate records not throwing an exception
yes sqlite does not understand migrations well. In particular it
cannot alter table and change a column type. It just stores new values
according to the new type.

Massimo

On 1 Mag, 09:35, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl  
View profile  
 More options May 1, 10:48 am
From: Carl <carl.ro...@gmail.com>
Date: Fri, 1 May 2009 07:48:33 -0700 (PDT)
Local: Fri, May 1 2009 10:48 am
Subject: Re: duplicate records not throwing an exception
My target database is Google's AppEngine. Do you know if it handles
migrations smoothly?

On May 1, 3:46 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mdipierro  
View profile  
 More options May 1, 11:47 am
From: mdipierro <mdipie...@cs.depaul.edu>
Date: Fri, 1 May 2009 08:47:08 -0700 (PDT)
Local: Fri, May 1 2009 11:47 am
Subject: Re: duplicate records not throwing an exception
On GAE there is no concept of alter table so you can add columns and
you can drop (they will not be dropped, just ignored). You can change
some attributes of a column (like length) since they are ignored
anyway. Some migrations will not work.

Massimo

On May 1, 9:48 am, Carl <carl.ro...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google