New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autostripped strings are not validated correctly for Required attributes #176

Closed
andreymal opened this Issue Mar 28, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@andreymal

andreymal commented Mar 28, 2016

from pony.orm import *

db = Database()

class TestPost(db.Entity):
    title = Required(str)

db.bind('sqlite', ':memory:')
db.generate_mapping(create_tables=True)
sql_debug(True)

with db_session:
    post = TestPost(title=' ')


with db_session:
    TestPost.select().first()
$ python ponyfail.py
GET CONNECTION FROM THE LOCAL POOL
BEGIN IMMEDIATE TRANSACTION
INSERT INTO "TestPost" ("title") VALUES (?)
['']

COMMIT
RELEASE CONNECTION
GET CONNECTION FROM THE LOCAL POOL
SWITCH TO AUTOCOMMIT MODE
SELECT "tp"."id", "tp"."title"
FROM "TestPost" "tp"
ORDER BY 1
LIMIT 1

ROLLBACK
RELEASE CONNECTION
Traceback (most recent call last):
...
  File "/usr/lib/python3.5/site-packages/pony/orm/core.py", line 2186, in validate
    if obj is None: throw(ValueError, 'Attribute %s is required' % attr)
  File "/usr/lib/python3.5/site-packages/pony/utils.py", line 103, in throw
    raise exc
ValueError: Attribute TestPost.title is required
@andreymal

This comment has been minimized.

Show comment
Hide comment
@andreymal

andreymal Mar 29, 2016

Oops, fixed typo at last line, but bug still exists

andreymal commented Mar 29, 2016

Oops, fixed typo at last line, but bug still exists

@kozlovsky kozlovsky closed this in 02bc2b7 Apr 1, 2016

@kozlovsky

This comment has been minimized.

Show comment
Hide comment
@kozlovsky

kozlovsky Apr 1, 2016

Member

Fixed

Member

kozlovsky commented Apr 1, 2016

Fixed

@kozlovsky kozlovsky added the bug label Apr 1, 2016

@kozlovsky kozlovsky added this to the 0.6.5 milestone Apr 1, 2016

@kozlovsky kozlovsky self-assigned this Apr 1, 2016

@kozlovsky kozlovsky changed the title from Autostripped string is not validated before insert/update to Autostripped strings are not validated correctly for Required attributes Apr 4, 2016

kozlovsky added a commit that referenced this issue Apr 4, 2016

Pony ORM Release 0.6.5 (2016-04-04)
# Improvements

* Fixes #172: Query prefetch() method should load specified lazy attributes right in the main query if possible

# Bugfixes

* Fixes #168: Incorrect caching when slicing the same query multiple times
* Fixes #169: When py_check() returns False, Pony should truncate too large values in resulting ValueError message
* Fixes #171: AssertionError when saving changes of multiple objects
* Fixes #176: Autostripped strings are not validated correctly for Required attributes

See blog post for more detailed information: https://blog.ponyorm.com/2016/04/04/pony-orm-release-0-6-5/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment