forked from ponyorm/pony
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix KeyError on flush after obj.set(**kwargs)
- Loading branch information
Showing
2 changed files
with
32 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,22 @@ class Group(db.Entity): | |
students = Set('Student') | ||
|
||
class Student(db.Entity): | ||
id = PrimaryKey(int) | ||
name = Required(unicode) | ||
age = Optional(int) | ||
passport = Optional("Passport") | ||
scholarship = Required(Decimal, default=0) | ||
picture = Optional(buffer, lazy=True) | ||
email = Required(unicode, unique=True) | ||
phone = Optional(unicode, unique=True) | ||
courses = Set('Course') | ||
group = Optional('Group') | ||
|
||
class Passport(db.Entity): | ||
id = PrimaryKey(int) | ||
number = Required(str, unique=True) | ||
person = Required(Student) | ||
|
||
class Course(db.Entity): | ||
id = PrimaryKey(int) | ||
name = Required(unicode) | ||
|
@@ -43,6 +50,7 @@ def setUpClass(cls): | |
s1 = Student(id=1, name='S1', age=19, email='[email protected]', group=g1) | ||
s2 = Student(id=2, name='S2', age=21, email='[email protected]', group=g1) | ||
s3 = Student(id=3, name='S3', email='[email protected]', group=g2) | ||
p1 = Passport(id=1, number='111', person=1) | ||
c1 = Course(id=1, name='Math', semester=1) | ||
c2 = Course(id=2, name='Math', semester=2) | ||
c3 = Course(id=3, name='Physics', semester=1) | ||
|
@@ -114,6 +122,22 @@ def test_set4(self): | |
s1 = Student[1] | ||
s1.set(name='New name', email='[email protected]') | ||
|
||
def test_set5(self): | ||
g2 = Group[1] | ||
s2 = Student._get_by_raw_pkval_((1,)) | ||
s2.set(age=20, group=None) | ||
db.flush() | ||
|
||
def test_set6(self): | ||
s2 = Student._get_by_raw_pkval_((1,)) | ||
s2.set(age=20, group=None, picture=None) | ||
db.flush() | ||
|
||
def test_set7(self): | ||
s2 = Student._get_by_raw_pkval_((2,)) | ||
s2.set(age=22, passport=None) | ||
db.flush() | ||
|
||
def test_validate_1(self): | ||
s4 = Student(id=3, name='S4', email='[email protected]', group=1) | ||
|
||
|