Re: Allowing validation to pass for partial post values?

Iain Duncan <[email protected]> Fri, 27 Jul 2012 13:15:05 -0700
Newsgroups gmane.comp.python.formencode
Message-ID <CAN9NcLw1u=BxwnkgOUYF8=QLJR-uRUBfMS=XWH_QMnfZVcypmw@mail.gmail.com>
--===============3234518085036334516==
Content-Type: multipart/alternative; boundary=f46d044517412db9e504c5d55e10

--f46d044517412db9e504c5d55e10
Content-Type: text/plain; charset=ISO-8859-1

Hi Chris, I'm not sure if what you're suggesting is what I want. Here's a
clarification, maybe you can tell me.

The schema for my tests looks like:

class PersonValidationSchema(ValidationSchema):
    """validation schema for resource Person"""
    name_first = v.UnicodeString(not_empty=True)
    name_last = v.UnicodeString(not_empty=True)
    birthdate = IsoDate()

The names can't be empty, which is correct, because I want errors if we're
sent post values with empty strings for them. But what I need to be able to
do for Dojo is receive and *pass* a post dict that is missing a name_last
key, and get a validated dict also missing a name_last key. When that
happens, the write to the db will update only the fields that have keys in
my post vals, and ignore the others ( not setting them to none or any
default value).

Does that makes sense? Is that something I can do with what you are
suggesting?

thanks!
Iain


On Fri, Jul 27, 2012 at 1:04 PM, Chris Lambacher <[email protected]>wrote:

> Hi Iain,
>
> If what you want is to do is conditionally require some values then what
> you are looking for is RequireIfMissing/RequireIfPresent which you put in
> the chained_validators for the Schema:
>
> http://www.formencode.org/en/latest/modules/validators.html#formencode.validators.RequireIfMissing
>
>
> Note that it won't block other validation errors, so if you have an Int
> validator and get a string, that validator will still give you an error
> even if it will ultimately be ignored.
>
> If that is a concern you can do a pre_validator that modifies / replaces
> the value dict such that it includes only the values that should be kept.
>
> -Chris
>
> On Fri, Jul 27, 2012 at 2:39 PM, Iain Duncan <[email protected]>wrote:
>
>> Hi, I'm using form encode for validation, and am building a ReST back end
>> for use with Dojo data stores. the Dojo system wants to be able to use PUT
>> requests with partial lists of params, and I'm trying to figure out best to
>> do that. So if I have a schema, and some keys are missing, I want it to
>> 'pass', with the values dictionary as is, rather than having the values
>> dict have values for the missing keys that come from using if_missing='foo'.
>>
>> Is there way to do that without resorting to hackery like inspecting the
>> errors and discarding all the ones that are missing value errors?
>>
>> thanks
>> Iain
>>
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> FormEncode-discuss mailing list
>> FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
>> https://lists.sourceforge.net/lists/listinfo/formencode-discuss
>>
>>
>
>
> --
> Christopher Lambacher
> [email protected]
>

--f46d044517412db9e504c5d55e10
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Hi Chris, I&#39;m not sure if what you&#39;re suggesting is what I want. He=
re&#39;s a clarification, maybe you can tell me.<div><br></div><div>The sch=
ema for my tests looks like:</div><div><br></div><div><div>class PersonVali=
dationSchema(ValidationSchema):</div>
<div>=A0 =A0 &quot;&quot;&quot;validation schema for resource Person&quot;&=
quot;&quot;</div><div>=A0 =A0 name_first =3D v.UnicodeString(not_empty=3DTr=
ue)</div><div>=A0 =A0 name_last =3D v.UnicodeString(not_empty=3DTrue)</div>=
<div>=A0 =A0 birthdate =3D IsoDate()</div>
<div><br></div><div>The names can&#39;t be empty, which is correct, because=
 I want errors if we&#39;re sent post values with empty strings for them. B=
ut what I need to be able to do for Dojo is receive and *pass* a post dict =
that is missing a name_last key, and get a validated dict also missing a na=
me_last key. When that happens, the write to the db will update only the fi=
elds that have keys in my post vals, and ignore the others ( not setting th=
em to none or any default value).</div>
<div><br></div><div>Does that makes sense? Is that something I can do with =
what you are suggesting?</div><div><br></div><div>thanks!</div><div>Iain</d=
iv><div><br></div><br><div class=3D"gmail_quote">On Fri, Jul 27, 2012 at 1:=
04 PM, Chris Lambacher <span dir=3D"ltr">&lt;<a href=3D"mailto:chris@katean=
dchris.net" target=3D"_blank">[email protected]</a>&gt;</span> wrote:<=
br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div>Hi=A0Iain,</div><div><br></div>If what =
you want is to do is conditionally require some values then what you are lo=
oking for is RequireIfMissing/RequireIfPresent which you put in the chained=
_validators for the Schema:<div>

<a href=3D"http://www.formencode.org/en/latest/modules/validators.html#form=
encode.validators.RequireIfMissing" target=3D"_blank">http://www.formencode=
.org/en/latest/modules/validators.html#formencode.validators.RequireIfMissi=
ng</a>=A0</div>
<div>
<br></div><div>Note that it won&#39;t block other validation errors, so if =
you have an Int validator and get a string, that validator will still give =
you an error even if it will ultimately be ignored.</div><div><br></div>

<div>If that is a concern you can do a pre_validator that modifies / replac=
es the value dict such that it includes only the values that should be kept=
.</div><div><br></div><div>-Chris<br><br><div class=3D"gmail_quote"><div>
<div class=3D"h5">On Fri, Jul 27, 2012 at 2:39 PM, Iain Duncan <span dir=3D=
"ltr">&lt;<a href=3D"mailto:[email protected]" target=3D"_blank">ia=
[email protected]</a>&gt;</span> wrote:<br>
</div></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div><div class=3D"h5">Hi, I&#39=
;m using form encode for validation, and am building a ReST back end for us=
e with Dojo data stores. the Dojo system wants to be able to use PUT reques=
ts with partial lists of params, and I&#39;m trying to figure out best to d=
o that. So if I have a schema, and some keys are missing, I want it to &#39=
;pass&#39;, with the values dictionary as is, rather than having the values=
 dict have values for the missing keys that come from using if_missing=3D&#=
39;foo&#39;.<div>


<br></div><div>Is there way to do that without resorting to hackery like in=
specting the errors and discarding all the ones that are missing value erro=
rs?</div><div><br></div><div>thanks</div><span><font color=3D"#888888"><div=
>

Iain</div>
</font></span><br></div></div>---------------------------------------------=
---------------------------------<br>
Live Security Virtual Conference<br>
Exclusive live event will cover all the ways today&#39;s security and<br>
threat landscape has changed and how IT managers can respond. Discussions<b=
r>
will include endpoint security, mobile security and the latest in malware<b=
r>
threats. <a href=3D"http://www.accelacomm.com/jaw/sfrnl04242012/114/5012226=
3/" target=3D"_blank">http://www.accelacomm.com/jaw/sfrnl04242012/114/50122=
263/</a><br>_______________________________________________<br>
FormEncode-discuss mailing list<br>
<a href=3D"mailto:FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org" target=3D"_blan=
k">FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/formencode-discuss"=
 target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/formencode-=
discuss</a><br>
<br></blockquote></div><span class=3D"HOEnZb"><font color=3D"#888888"><br><=
br clear=3D"all"><div><br></div>-- <br>Christopher Lambacher<br><a href=3D"=
mailto:[email protected]" target=3D"_blank">[email protected]</a>=
<br>
</font></span></div>
</blockquote></div><br></div>

--f46d044517412db9e504c5d55e10--


--===============3234518085036334516==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
--===============3234518085036334516==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/formencode-discuss

--===============3234518085036334516==--