Check self.id against None before comparing to 0
issue5590 review25111002
This commit is contained in:
1 parent
703b21292d
commit
33224eeaa3
4 files changed
+42
-1
No files matched your search
@@ -388,7 +388,7 @@ class Model(WarningErrorMixin, URLMixin, PoolBase):
|
||||
return u'%s,%s' % (self.__name__, self.id)
|
||||
|
||||
def __repr__(self):
|
||||
if self.id < 0:
|
||||
if self.id is None or self.id < 0:
|
||||
return "Pool().get('%s')(**%s)" % (self.__name__,
|
||||
repr(self._default_values))
|
||||
else:
|
||||
|
||||
@@ -101,6 +101,7 @@ def register():
|
||||
Binary,
|
||||
BinaryDefault,
|
||||
BinaryRequired,
|
||||
Model,
|
||||
Singleton,
|
||||
URLObject,
|
||||
ModelStorage,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from trytond.model import ModelSingleton, ModelSQL, UnionMixin, fields
|
||||
|
||||
__all__ = [
|
||||
'Model',
|
||||
'Singleton', 'URLObject',
|
||||
'ModelStorage',
|
||||
'ModelSQLRequiredField', 'ModelSQLTimestamp', 'ModelSQLFieldSet',
|
||||
@@ -12,6 +13,12 @@ __all__ = [
|
||||
]
|
||||
|
||||
|
||||
class Model(ModelSQL):
|
||||
'Model'
|
||||
__name__ = 'test.model'
|
||||
name = fields.Char('Name')
|
||||
|
||||
|
||||
class Singleton(ModelSingleton, ModelSQL):
|
||||
'Singleton'
|
||||
__name__ = 'test.singleton'
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of this
|
||||
# repository contains the full copyright notices and license terms.
|
||||
|
||||
import unittest
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import install_module, with_transaction
|
||||
|
||||
|
||||
class ModelTestCase(unittest.TestCase):
|
||||
'Test Model'
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
install_module('tests')
|
||||
|
||||
@with_transaction()
|
||||
def test_repr(self):
|
||||
'Test repr'
|
||||
pool = Pool()
|
||||
Model = pool.get('test.model')
|
||||
|
||||
record = Model(name='foo')
|
||||
self.assertEqual(
|
||||
repr(record), "Pool().get('test.model')(**{'name': 'foo'})")
|
||||
|
||||
record.save()
|
||||
self.assertEqual(
|
||||
repr(record), "Pool().get('test.model')(%s)" % record.id)
|
||||
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromTestCase(ModelTestCase)
|
||||
Reference in new issue
Block a user