# How to resolve AssertionType error

**URL:** <https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222>\
**Category:** Developer\
**Created:** [January 24, 2020, 10:49am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222 "2020-01-24T10:49:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)\
**Post date:** [January 24, 2020, 10:49am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/1 "2020-01-24T10:49:08Z")

</div>

```python
fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2') >= 50 and ~Eval('fio_2') <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

```

On executing above code error showing up below:  
File “/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py”, line 300, in **init**  
‘statement must be an integer or a float’  
AssertionError: statement must be an integer or a float

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [January 24, 2020, 11:10am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/2 "2020-01-24T11:10:22Z")

</div>

PYSON Eval uses the default value to determine the statement type. If no default value is set it uses an empty string. In your case the default value is a string (due to the empty string default value) which raises the AssertionError due to a comparision between char and integer.

You should specify a float default value for your code in order to resolve the ArrertionError. Something like:

```python
fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2',0) >= 50 and ~Eval('fio_2',0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

```

Note that I’ve converted `Eval('fio_2')` into `Eval('fio_2', 0)`

Hope it helps!

---

<div class="post-metadata">

**Author:** ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)\
**Post date:** [January 24, 2020, 11:31am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/3 "2020-01-24T11:31:05Z")

</div>

Sir, how will I specify a float default value for my code. Any guidance will be a great help.

---

<div class="post-metadata">

**Author:** ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)\
**Post date:** [January 24, 2020, 12:35pm UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/4 "2020-01-24T12:35:24Z")

</div>

> [@prashasti.sharma](#):
>
> how will I specify a float default value for my code.

[Combine the word `default` and the field name into a function](https://docs.tryton.org/projects/server/en/latest/topics/models/fields_default_value.html). Like:

```auto
fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2') >= 50 and ~Eval('fio_2') <= 100,
    }, depends=['fio_2'])

@staticmethod
def default_fio_2():
    return 40.0

```

---

<div class="post-metadata">

**Author:** ![dabada83](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/dabada83/32/67_2.png) [@dabada83](https://discuss.tryton.org/u/dabada83)\
**Post date:** [January 24, 2020, 6:13pm UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/5 "2020-01-24T18:13:52Z")

</div>

I think on Pyson you should use ‘&’ instead ‘and’

---

<div class="post-metadata">

**Author:** ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)\
**Post date:** [January 25, 2020, 5:25am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/6 "2020-01-25T05:25:07Z")

</div>

I have coded the code like given below:

```python
fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2', 0) >= 50 and ~Eval('fio_2', 0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')
@staticmethod
    def default_fio_2():
        return 0.0

```

But still the same error is coming:

```
File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 476, in <module>
    class PatientProfile(ModelSQL, ModelView):
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 742, in PatientProfile
    'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 67, in __ge__
    return Greater(self, other, True)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 301, in __init__
    'statement must be an integer or a float'
AssertionError: statement must be an integer or a float

```

Any further recommendation from your side will be helpful.

---

<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:** [January 25, 2020, 9:38am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/7 "2020-01-25T09:38:04Z")

</div>

As @dabada83 said:

> [@prashasti.sharma](#):
>
> ‘invisible’: ~Eval(‘fio\_2’, 0) \>= 50 and ~Eval(‘fio\_2’, 0) \<= 100,

must use `&` instead of `and` like

```python
'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100

```

---

<div class="post-metadata">

**Author:** ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)\
**Post date:** [January 27, 2020, 7:39am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/8 "2020-01-27T07:39:45Z")

</div>

Sir, i have written the code like this, as follows:

```
fio_2 = fields.Integer('FIO₂(󠀥%)')
    a_gradient = fields.Integer('A-a gradient', states={
        'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
    }, depends=['fio_2'])
    a_gradient_point = fields.Function(
        fields.Integer('A-a gradient Points', states={
            'invisible': ~Eval('a_gradient'),
        }, depends=['a_gradient']),
        'on_change_with_a_gradient_point')

    @fields.depends('a_gradient')
    def on_change_with_a_gradient_point(self, name=None):
        result = 0
        if self.a_gradient in range(350, 500):
            result = 3
        elif self.a_gradient in range(200, 350):
            result = 2
        elif self.a_gradient in range(500, ):
            result = 4
        else:
            result = 0
        return result

    pao2 = fields.Integer('PaO2', states={
        'invisible': ~Eval('fio_2', 0) >= 0 & ~Eval('fio_2', 0) <= 49,
    }, depends=['fio_2'])
    pao2_point = fields.Function(
        fields.Integer('PaO2 Points', states={
            'invisible': ~Eval('pao2'),
        }, depends=['pao2']),
        'on_change_with_pao2_point')

    @fields.depends('pao2')
    def on_change_with_pao2_point(self, name=None):
        result = 0
        if self.pao2 in range(61, 71):
            result = 1
        elif self.pao2 in range(55, 61):
            result = 3
        else:
            result = 4
        return result

    @staticmethod
    def default_fio_2():
        return 0

```

On installing the module the error showing up as:

```
7602 140145196042048 [2020-01-27 07:28:37,148] INFO trytond.backend.postgresql.database connect to "anesticu"
Eval('id', 0)
7602 140145196042048 [2020-01-27 07:28:37,252] WARNING py.warnings /home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/wsgi.py:150: DeprecationWarning: 'werkzeug.wsgi.SharedDataMiddleware' has moved to 'werkzeug.middleware.shared_data.SharedDataMiddleware'. This import is deprecated as of version 0.15 and will be removed in version 1.0.
  app.wsgi_app = SharedDataMiddlewareIndex(app.wsgi_app, static_files)

7602 140145196042048 [2020-01-27 07:28:37,274] INFO trytond.modules ir:registering classes
7602 140145196042048 [2020-01-27 07:28:37,275] INFO trytond.modules res:registering classes
7602 140145196042048 [2020-01-27 07:28:37,275] INFO trytond.modules anaesthesiology_intensive_care:registering classes
Not(Bool(Eval('fio_2', 0)))
Traceback (most recent call last):
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/ __init__.py", line 53, in import_module
    module = importlib.import_module(fullname)
  File "/usr/lib/python3.6/importlib/ __init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'trytond.modules.anaesthesiology_intensive_care'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../../../../trytond/bin/trytond-admin", line 21, in <module>
    admin.run(options)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/admin.py", line 54, in run
    activatedeps=options.activatedeps)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pool.py", line 149, in init
    self.start()
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pool.py", line 102, in start
    register_classes()
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/ __init__.py", line 331, in register_classes
    the_module = import_module(module)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/modules/ __init__.py", line 77, in import_module
    module = spec.loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/ __init__.py", line 5, in <module>
    from .anaesthesiology_intensive_care import *
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 476, in <module>
    class PatientProfile(ModelSQL, ModelView):
  File "/home/khushboo/workspace/tryton/tryton50/lib/python3.6/site-packages/trytond_anaesthesiology_intensive_care-5.0.0-py3.6.egg/trytond/modules/anaesthesiology_intensive_care/anaesthesiology_intensive_care.py", line 742, in PatientProfile
    'invisible': ~Eval('fio_2', 0) >= 50 & ~Eval('fio_2', 0) <= 100,
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 67, in __ge__
    return Greater(self, other, True)
  File "/home/khushboo/workspace/tryton/tryton50/src/trytond/trytond/pyson.py", line 301, in __init__
    'statement must be an integer or a float'
AssertionError: statement must be an integer or a float

```

Any further help will be highly appreciable.

---

<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:** [January 27, 2020, 8:09am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/9 "2020-01-27T08:09:55Z")

</div>

Indeed `~` is equivalent to “not” so it is a Boolean expression type which can not be compared to integers.  
So I guess you want:

```auto
'invisible': (Eval('fio_2', 0) < 50) & (Eval('fio_2', 0) > 100)

```

Check the parenthesis because they are required as `&` operator has binary operator has precedence over comparison operators.

---

<div class="post-metadata">

**Author:** ![prashasti.sharma](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/p/58f4c7/32.png) [@prashasti.sharma](https://discuss.tryton.org/u/prashasti.sharma)\
**Post date:** [January 27, 2020, 8:58am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/10 "2020-01-27T08:58:33Z")

</div>

Thanks @ced sir, it worked.

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [February 26, 2020, 8:58am UTC](https://discuss.tryton.org/t/how-to-resolve-assertiontype-error/2222/11 "2020-02-26T08:58:41Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
