Andrii,

I believe I have a fix for this.  It covers minInclusive,
maxInclusive, minExclusive, and maxExclusive for each of xs:date,
xs:time, and xs:dateTime.

This change turns out to require changing only a few lines of code.
But, I had to try several bad, or at least poor ways before backing
myself into a reasonably good way.

I also added new unit test cases for the validation of the date/time
simpleType.

I've attached a patch against v. 2.22b, but you will likely find it
easier to use Mercurial to clone (or pull) these changes from
Bitbucket: https://bitbucket.org/dkuhlman/generateds

Please let me know what you think of this fix and whether it works
for you.

Thanks again for reporting this and for pointing me at a solution.

Dave

On Fri, Apr 22, 2016 at 04:53:35PM +0100, Andrii Iudin wrote:
> Dear Dave and generateDS mailing group,
> 
> After updating to the recent version 2.22a the generated Python source 
> code for structures appears to have a validation of xs:date elements.
> We have one with a facet minInclusive set to '2002-01-01'. The 
> previously used version 2.13a produced just
>      def validate_dateType(self, value):
>          # Validate type dateType, a restriction on xs:date.
>          pass
> 
> However, now it is defined as
>      def validate_dateType(self, value):
>          # Validate type dateType, a restriction on xs:date.
>          if value is not None and Validate_simpletypes_:
>              if value < 2002-01-01:
>                  warnings_.warn('Value "%(value)s" does not match xsd 
> minInclusive restriction on dateType' % {"value" : value} )
> 
> This comparison results in "TypeError: can't compare datetime.date to int".
> 
> Please could you tell if there is a fix available for this or a 
> parameter that can be adjusted when generating the code?
> 
> Thank you and best regards,
> Andrii
> 
> ------------------------------------------------------------------------------
> Find and fix application performance issues faster with Applications Manager
> Applications Manager provides deep performance insights into multiple tiers of
> your business applications. It resolves application problems quickly and
> reduces your MTTR. Get your free trial!
> https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users

-- 

Dave Kuhlman
http://www.davekuhlman.org
diff -r 46ae1ab16514 generateDS.py
--- a/generateDS.py     Fri Apr 22 09:58:47 2016 +0300
+++ b/generateDS.py     Tue Apr 26 16:07:38 2016 -0700
@@ -4254,6 +4254,19 @@
     return st
 
 
+def get_target_value(default, stName):
+    stObj = SimpleTypeDict.get(stName)
+    targetValue = default
+    if stObj is not None:
+        if stObj.getBase() == DateType:
+            targetValue = "self.gds_parse_date('{}')".format(default)
+        elif stObj.getBase() == TimeType:
+            targetValue = "self.gds_parse_time('{}')".format(default)
+        elif stObj.getBase() == DateTimeType:
+            targetValue = "self.gds_parse_datetime('{}')".format(default)
+    return targetValue
+
+
 # Generate validation code for each restriction.
 # Recursivly call to process possible chain of base types.
 def processValidatorBodyRestrictions(
@@ -4362,8 +4375,9 @@
             if 'string' in base:
                 valuestring = 'len(str(value))'
                 toencode = '% {"value" : value.encode("utf-8")}'
+            targetValue = get_target_value(minIncl, stName)
             s1 += "            if %(valuestring)s < %(minIncl)s:\n" % {
-                'minIncl': minIncl, "valuestring": valuestring}
+                'minIncl': targetValue, "valuestring": valuestring}
             s1 += ("                warnings_.warn('Value \"%(val)s\" "
                    "does not match xsd minInclusive restriction on "
                    "%(typename)s' %(express)s )\n" % {
@@ -4382,8 +4396,9 @@
             if 'string' in base:
                 valuestring = 'len(str(value))'
                 toencode = '% {"value" : value.encode("utf-8")}'
+            targetValue = get_target_value(maxIncl, stName)
             s1 += "            if %(valuestring)s > %(maxIncl)s:\n" % {
-                'maxIncl': maxIncl, "valuestring": valuestring}
+                'maxIncl': targetValue, "valuestring": valuestring}
             s1 += ("                warnings_.warn('Value \"%(val)s\" "
                    "does not match xsd maxInclusive restriction on "
                    "%(typename)s' %(express)s )\n" % {
@@ -4402,8 +4417,9 @@
             if 'string' in base:
                 valstr = 'len(str(value))'
                 toencode = '% {"value" : value.encode("utf-8")}'
+            targetValue = get_target_value(minExclusive, stName)
             s1 += "            if %(valstr)s <= %(minExclusive)s:\n" % {
-                'minExclusive': minExclusive, "valstr": valstr}
+                'minExclusive': targetValue, "valstr": valstr}
             s1 += ("                warnings_.warn('Value \"%(val)s\" "
                    "does not match xsd minExclusive restriction on "
                    "%(typename)s' %(express)s )\n" % {
@@ -4422,8 +4438,9 @@
             if 'string' in base:
                 valstr = 'len(str(value))'
                 toencode = '% {"value" : value.encode("utf-8")}'
+            targetValue = get_target_value(maxExclusive, stName)
             s1 += "            if %(valstr)s >= %(maxExclusive)s:\n" % {
-                'maxExclusive': maxExclusive, "valstr": valstr}
+                'maxExclusive': targetValue, "valstr": valstr}
             s1 += ("                warnings_.warn('Value \"%(val)s\" "
                    "does not match xsd maxExclusive restriction on "
                    "%(typename)s' %(express)s )\n" % {
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to