From ec21f72ce3b51d113013a88ca4da9e7f960ad661 Mon Sep 17 00:00:00 2001 From: Tim Nyborg Date: Fri, 21 Jul 2017 10:20:08 +0100 Subject: [PATCH 1/2] Fixes #1691 Clone fields, but leave tables untouched in factory() --- gluon/sqlhtml.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index 0468c0f7..cdbff2d5 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -1919,8 +1919,15 @@ class SQLFORM(FORM): if 'table_name' in attributes: del attributes['table_name'] - return SQLFORM(DAL(None).define_table(table_name, *[field.clone() for field in fields]), - **attributes) + fields_with_clones = [] + for field in fields: + if isinstance(field, Field): + fields_with_clones.append(field.clone()) + else: + # We have a table, so pass it along + fields_with_clones.append(field) + + return SQLFORM(DAL(None).define_table(table_name, *fields_with_clones), **attributes) @staticmethod def build_query(fields, keywords): From d43604c3ff74a717086eef948db4699e86f6cea8 Mon Sep 17 00:00:00 2001 From: Tim Nyborg Date: Mon, 24 Jul 2017 10:15:12 +0100 Subject: [PATCH 2/2] List comprehension rather than loop I've now learned this is quicker --- gluon/sqlhtml.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/gluon/sqlhtml.py b/gluon/sqlhtml.py index cdbff2d5..f12ba004 100644 --- a/gluon/sqlhtml.py +++ b/gluon/sqlhtml.py @@ -1919,13 +1919,8 @@ class SQLFORM(FORM): if 'table_name' in attributes: del attributes['table_name'] - fields_with_clones = [] - for field in fields: - if isinstance(field, Field): - fields_with_clones.append(field.clone()) - else: - # We have a table, so pass it along - fields_with_clones.append(field) + # Clone fields, while passing tables straight through + fields_with_clones = [f.clone() if isinstance(f, Field) else f for f in fields] return SQLFORM(DAL(None).define_table(table_name, *fields_with_clones), **attributes)