# Singleton Model Error while running tests

**URL:** <https://discuss.tryton.org/t/singleton-model-error-while-running-tests/3225>\
**Category:** Developer\
**Created:** [September 16, 2020, 12:38pm UTC](https://discuss.tryton.org/t/singleton-model-error-while-running-tests/3225 "2020-09-16T12:38:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lpetiteauRDR](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@lpetiteauRDR](https://discuss.tryton.org/u/lpetiteauRDR)\
**Post date:** [September 16, 2020, 12:38pm UTC](https://discuss.tryton.org/t/singleton-model-error-while-running-tests/3225/1 "2020-09-16T12:38:03Z")

</div>

Good afternoon everyone,

I’m currently working on building a test environment (using ModuleTestCase suite tests).  
One of my models calls a fonction that requires a instance of singleton model - code below.

```auto
        >>> my_model_config= Pool().get('my_model.configuration').get_singleton()
        >>> value = my_model_config.field_boolean

```

The returned Error is the following :

```auto
	AttributeError: 'NoneType' object has no attribute 'field_boolean'

```

I understand that my\_model\_config is None, cause get\_singleton function did not find any matching  
object. But when I try to manually search for it inside my test environment, I successfully find an  
instance of my\_model\_config.

```auto
	>>> test_my_model_config = pool.get('my_model.configuration').search([], limit=1)[0]
	>>> print(test_my_model_config if test_my_model_config != None)
	Pool().get('my_model.configuration')(1)

```

Here is the definition of my\_model.configuration :

```auto
	>>> from trytond.model import ModelView, ModelSQL, ModelSingleton

	>>> __all__ = [
    	>>> 'Configuration',
    	>>> ]

	>>> class Configuration(ModelSingleton, modelSQL, modelView):
    	>>> 'My Model Configuration'

    	>>> __name__ = 'my_model.configuration'

    	>>> field_boolean = fields.Boolean('Attribute Boolean')
		...

```

I do not get where is the issue here. Hope that you can help me !  
Thank you by advance.

---

<div class="post-metadata">

**Author:** ![ced](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/ced/32/1237_2.png) [@ced](https://discuss.tryton.org/u/ced)\
**Post date:** [September 16, 2020, 2:23pm UTC](https://discuss.tryton.org/t/singleton-model-error-while-running-tests/3225/2 "2020-09-16T14:23:20Z")

</div>

This is because Tryton emulates a singleton even if there are no record saved in the table.  
Indeed you should not use `get_singleton` because it returns only saved singleton. Instead you should always instantiate a singleton with for example the id `1` (common practice).
