Please open a ticket about this. For now it should safe for you to change
the regex in the source. I assumed (incorrectly) that SQL did not allow
table/field names starting with a number.
Massimo
On Thursday, 13 September 2012 19:58:48 UTC-5, Adi wrote:
>
> for the convenience i pulled out both versions, and my suggested change:
> 1.99.7 cleanup:
> def cleanup(text):
> """
> validates that the given text is clean: only contains [0-9a-zA-Z_]
> """
>
> if re.compile('[^0-9a-zA-Z_]').findall(text):
> raise SyntaxError, \
> 'only [0-9a-zA-Z_] allowed in table and field names, received
> %s' \
> % text
> return text
>
> 2.08 cleanup:
>
> REGEX_ALPHANUMERIC = re.compile('^[a-zA-Z]\w*$')
>
> def cleanup(text):
> """
> validates that the given text is clean: only contains [0-9a-zA-Z_]
> """
> if not REGEX_ALPHANUMERIC.match(text):
> raise SyntaxError, 'invalid table or field name: %s' % text
> return text
>
>
> >>> REGEX_ALPHANUMERIC = re.compile('^[a-zA-Z]\w*$')
> >>> REGEX_ALPHANUMERIC.match('40')
> >>> print REGEX_ALPHANUMERIC.match('40')
> None
>
> i changed into this and all works good:
> >>> REGEX_ALPHANUMERIC = re.compile('^[0-9a-zA-Z]\w*$')
> >>> print REGEX_ALPHANUMERIC.match('40aaa_aa').span()
> (0, 8)
>
>
>
> On Thursday, September 13, 2012 8:28:43 PM UTC-4, Adi wrote:
>>
>> One of my fields is 40off_sh (legacy MySQL db), and all works fine in
>> 1.97. Seems like cleanup function in dal doesn't like the numeric part at
>> the beginning of field name, or I'm reading it wrong? I checked the table
>> and the field is in, so it's not missing.
>>
>> I can't change the field name, since it's used by other applications, so
>> not sure what would you recommend to do here?
>>
>> Thanks,
>> Adnan
>>
>> Traceback (most recent call last):
>> File "/opt/web-apps/web2py/gluon/restricted.py", line 209, in restricted
>> exec ccode in environment
>> File "/opt/web-apps/web2py/applications/thane_us/models/db_1_common.py",
>> line 182, in <module>
>> Field('40off_sh', 'boolean',),
>> File "/opt/web-apps/web2py/gluon/dal.py", line 8396, in __init__
>> self.name = fieldname = cleanup(fieldname)
>> File "/opt/web-apps/web2py/gluon/dal.py", line 4769, in cleanup
>> raise SyntaxError, 'invalid table or field name: %s' % text
>> SyntaxError: invalid table or field name: 40off_sh
>>
>>
>>
--