But it still fails for those that don't have email. The first one gets
inserted, and the rest do not.

I just recreated a simple version, and it will allow me to insert multiple
fields to None even if unique=True.

There is something else going on with my system that is causing the problem.

And it is where I set the email to "" if it is not a valid email, or a
duplicate email.

For some reason, when the email is "", it will pass IS_NOT_IN_DB, but it
will throw an exception if unique=True.

Also, the it happens the opposite way

When email is None, it does not pass IS_NOT_IN_DB, but it passes unique=True

I will need to make sure to insert None (null) into the database, and when I
check IS_NOT_IN_DB pass if email is None

SO to recap

db.define_table("persons", Field("email", "string", unique=True))

db.persons.insert(email="") #OK
db.persons.insert(email="") #Exception
db.persons.insert(email=None) #OK
db.persons.insert(email=None) #OK
db.persons.insert(email=None) #OK

(email, error) = IS_NOT_IN_DB(db, 'persons.email')("") # Value already in
database
(email, error) = IS_NOT_IN_DB(db, 'persons.email')(None) # Value already in
database

-Thadeus




On Mon, Oct 19, 2009 at 8:50 PM, mdipierro <[email protected]> wrote:

>
> I would suggest using both.
>
> On Oct 19, 6:44 pm, Thadeus Burgess <[email protected]> wrote:
> > It seems that it is failing because unique=True and there is already a
> Null
> > value inserted.
> >
> > Would you suggest using unique=True, or IS_NOT_IN_DB() ?
> >
> > -Thadeus
> >
> > On Mon, Oct 19, 2009 at 6:20 PM, mdipierro <[email protected]>
> wrote:
> >
> > > this is a database issue, not a web2py. This is why I often use
> > > requires=IS_NOT_EMPTY() instead of notnull=True.
> >
> > > Massimo
> >
> > > On Oct 19, 5:09 pm, Thadeus Burgess <[email protected]> wrote:
> > > > Starting from a fresh sqlite database, I am attempting to import 3k+
> > > records
> > > > from a custom csv file (not one generated by web2py)
> >
> > > > Each row, I validate the input from the file before insertion to the
> > > > database. If I have incorrect input I throw an exception, basically
> > > passing
> > > > the row from being inserted to the database.
> >
> > > >            email = row['Email'].lower()
> >
> > > >            email, error = IS_EMAIL()(email)
> >
> > > >             if error and email != "":
> > > >                 email = ""
> >
> > > >             email, error = IS_NOT_IN_DB(db,
> 'participant.email')(email)
> >
> > > >             if error and email != "":
> > > >                 raise Exception('Duplicated Email!!! {{{%s}}}' %
> > > > row['Email'])
> >
> > > > At the end, i go db.user.insert(email=email, name=name, etc=etc)
> >
> > > > The problem I am having, is email in the database declaration has
> > > > unique=True, and is triggering an exception when there is no email.
> >
> > > > New users to this system will always have an email, and it will
> always be
> > > > unique, but unfortunately, old users may not have emails, but must
> still
> > > > remain in the system until they give an email.
> >
> > > > Is the only solution to this problem not setting the Field to unique?
> >
> > > > -Thadeus
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to