Comments (16)
Problem could be back compatibility
from pydal.
it was that way. Then cleanup was relaxed to.... pretty anything.
Versions slipped by, and now we face a problem.
from pydal.
I agree, and we should have the same approach for situations such as:
db = DAL("sqlite:memory")
db.define_table('a', Field('1'))
raises
AttributeError: 'Field' object has no attribute 'iteritems'
while
db = DAL("sqlite:memory")
db.define_table('a', Field(1))
raises
SyntaxError: Field: invalid field name: 1, use rname for "funny" names
In addition, the following works at 'pydal' level:
db = DAL("sqlite:memory", migrate=False)
db.define_table("1", Field('a'))
but then it fails at 'db' level:
db = DAL("sqlite:memory")
db.define_table("1", Field('a'))
raises
sqlite3.OperationalError: near "1": syntax error
from pydal.
this should be fixed before the next release to avoid finding ourselves in 6 months locked-in for backward compatibility
from pydal.
I've moved this to 15.04 milestone. If anybody is interested into fixing this, let us know.
from pydal.
this is quite an easy fix, once we all agree. There's nothing documented in the book, so a clear and large statement in the CHANGELOG would suffice.
I didn't read anything conclusive on web2py-developers, but I strongly think that this should be closed once and for all.
I (re)vote for cleanup() restricting table and field names to valid python identifiers. If I'm not mistaken, this is the reference.
Pinging everybody for the call-to-arms: @mdipierro , @gi0baro , @michele-comitini , @abastardi , @ilvalle , @leonelcamara ... feel free to chime in.
from pydal.
+1 on @niphlod vote
from pydal.
ok, I think we can safely assume the only responsible for whining users would be me and @gi0baro . I'm ready to take the heat.
@gi0baro : ^[^\d\W]\w*\Z
should be the regex.
BTW: I'm not sure about leaving up the whole python3 range for identifiers, which accounts for unicode characters as well. I'd stay with valid python2 identifiers.
from pydal.
@niphlod ok with that
from pydal.
ok, will send a PR soon enough.
from pydal.
@gi0baro : another question... I'd go for the same routine for both tablenames and fieldnames, which is basically:
- a str
- a valid python identifier
- not a python keyword
- not starting with underscore
- not containing dots
table would have also the restriction of not being a yet-existing attribute of DAL.
tl;dr: adding "a valid python identifier" constraint to the existing one on Table and all of the above for Field
from pydal.
umpf. quite there. How the heck should we check that è
is not a str in python3 ? Meaning... we don't check for Field and Tablenames in python2 to be valid basestr
that would make things easier porting to python3... we only check with isinstance(obj, str)
. How can we make a validation on python3 for the same thing ?
from pydal.
@niphlod sorry, I was AFK. Anyway, I'm missing your point, since
isinstance('è', str)
is True
both on python 2 and python 3. And on python 2 isinstance('è', basestring)
is True
as well.
If we want to remove special characters I think we should use a regex.
from pydal.
right ........ will do this evening.
from pydal.
sorry if I chime in late
@niphlod, does this help?
https://stackoverflow.com/questions/5474008/regular-expression-to-confirm-whether-a-string-is-a-valid-identifier-in-python
2015-05-20 10:40 GMT+02:00 niphlod [email protected]:
right ........ will do this evening.
—
Reply to this email directly or view it on GitHub
#67 (comment).
from pydal.
unfortunately not. in py3 it would allow also unicode, since \W is in. Seeing the code, I won't touch "cleanup()" as it seems that the validation is both in Table and Field __init__
I'm in a place where no python exist but I think I'll refactor a bit those checks and just leave ^[^\d_][_0-9a-zA-Z]+$
#current
if (not isinstance(tablename, str) or tablename[0] == '_'
or hasattr(DAL, tablename) or '.' in tablename
or REGEX_PYTHON_KEYWORDS.match(tablename)
):
#will probably become
# in regex.py
NEWREGEX = re.compile('^[^\d_][_0-9a-zA-Z]+$')
....
if (not isinstance(tablename, basestr) or hasattr(DAL, tablename)
or NEWREGEX.match(tablename)
or REGEX_PYTHON_KEYWORDS.match(tablename)
):
from pydal.
Related Issues (20)
- GHSL-2021-116 HOT 1
- Fix unable to parse csv file in web2py break CSV parsing when dynamic upload is used
- MSSQL adapter, tableX_view.insert (..) + trigger INSTEAD OF INSERT, .lastrowid (), "SELECT SCOPE_IDENTITY ()", return long (../ None / ..)
- NotNullViolation on PostgreSQL migration of populated table with a notnull field
- The user name or password contains @, unable to connect to MySQL HOT 4
- Deprecation imports google.appengine.api.rdbms in _gae and google adapter HOT 1
- Upgrade to python3 datastore adapter. Help
- problem with .contains() when passing list as argument HOT 1
- pool_size and leaking connections on PostgreSQL
- erro calling db.uuid method HOT 1
- count field in restapi HOT 1
- non-database upload field fails to build filename
- web2py_filesystem Updates/Corrections
- REGEXP_LIKE missing parameter "match_parameter" in oracle
- Incorrect sqlite placeholder for InDBMigrator
- Database is locked, attempts not working
- Error in the class FireBird
- import_from_csv_file fails if export_to_csv_file with ref id column with gaps
- PyDAL for Azure MySQL
- PyDAL for Redis
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pydal.