define_table number of arguments limited to 255

94 views
Skip to first unread message

Richard

unread,
Oct 3, 2017, 3:22:57 PM10/3/17
to web2py-developers
Hello,

I kind of it an limit... I was refactoring some model definition and merging multiple tables into one and I had this error :

Traceback (most recent call last):
  File "/web2py/gluon/restricted.py", line 226, in restricted
    ccode = compile2(code, layer)
  File "/web2py/gluon/restricted.py", line 209, in compile2
    return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec')
  File "applications/sgddms/models/result.py", line 4
    db.define_table('table_name',
SyntaxError: more than 255 arguments


From my limited investigation it appears to come from compile2 function : https://github.com/web2py/web2py/blob/9f69ab9753ce32dba1174b02181e7bbf9ff0987a/gluon/restricted.py#L204


Where python bytecode compilation impose a limit over the number of positional arguments supported by a given object... It appears that it could be workaround using *args or **kwargs, but I guess in or case it wouldn't work to refactor pyDAL to avoid this limit as I guess we use positional arguments to determine where fields appears in form...

Can we fix that in order to support max amount of columns supported by given database engine (postgres = 1000 to my knowledge)??

Thanks

Richard

Anthony

unread,
Oct 4, 2017, 10:55:31 AM10/4/17
to web2py-developers
It's a Python limitation -- what could we do to fix it? Can't you put your fields in a list and then do:

db.define_table('mytable', *list_of_fields)

Anthony

Richard Vézina

unread,
Oct 4, 2017, 1:34:44 PM10/4/17
to web2py-d...@googlegroups.com
Maybe... Will try that... Do you see any drawback of using definte_table that  way??

Richard

--
-- mail from:GoogleGroups "web2py-developers" mailing list
make speech: web2py-developers@googlegroups.com
unsubscribe: web2py-developers+unsubscribe@googlegroups.com
details : http://groups.google.com/group/web2py-developers
the project: http://code.google.com/p/web2py/
official : http://www.web2py.com/
---
You received this message because you are subscribed to the Google Groups "web2py-developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py-developers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Richard Vézina

unread,
Oct 5, 2017, 4:07:14 PM10/5/17
to web2py-d...@googlegroups.com
Seems to work just fine so far...

Richard

Anthony

unread,
Oct 5, 2017, 5:56:58 PM10/5/17
to web2py-developers
On Wednesday, October 4, 2017 at 1:34:44 PM UTC-4, Richard wrote:
Maybe... Will try that... Do you see any drawback of using definte_table that  way??

No.

Anthony

unread,
Oct 5, 2017, 5:59:06 PM10/5/17
to web2py-developers
Note, here is an example where this pattern is used in the web2py code base:

Richard Vézina

unread,
Oct 10, 2017, 10:32:26 AM10/10/17
to web2py-d...@googlegroups.com
Great!

I am happy this one is a no brainer, I was afraid to have to work another solution or refactor actual model that I intended to use...

Thanks and regards Anthony

Richard

--
Reply all
Reply to author
Forward
0 new messages