# NotImplementedError: On table\_query

**URL:** <https://discuss.tryton.org/t/notimplementederror-on-table-query/2377>\
**Category:** Developer\
**Created:** [February 26, 2020, 2:22pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377 "2020-02-26T14:22:05Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 26, 2020, 2:22pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/1 "2020-02-26T14:22:05Z")

</div>

What does this error mean in Tryton 5.x?  
We haven’t seen it in Tryton 4.x.

---

<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:** [February 26, 2020, 2:33pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/2 "2020-02-26T14:33:47Z")

</div>

> [@bell](#):
>
> What does this error mean in Tryton 5.x?

It means that you are trying to create, write or delete a record of a table\_query model, which is an operation that is not implemented.

On which model do you get this error?

> [@bell](#):
>
> We haven’t seen it in Tryton 4.x.

This behaviour was the same on older series.

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 26, 2020, 2:43pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/3 "2020-02-26T14:43:43Z")

</div>

> [@pokoli](#):
>
> On which model do you get this error?

The model was discussed here:

> [@Report with dynamic columns and labels](https://discuss.tryton.org/t/report-with-dynamic-columns-and-labels/1139):
>
> Hi! There is a report in our application. Report’s columns are dynamically selected from the specified fields of the specified database tables. Description of the dynamic fields (columns) in our model: attr1 = fields.Char('Attr1') attr2 = fields.Char('Attr2') attr3 = fields.Char('Attr3') ... In the table\_query() selection is generated dynamically: tableA.join(tableB, ...) .join(tableC, ...) ... .select( tableA.field1.as\_('attr1'), tableB.field5.as\_('attr2'), tableC.field10.as\_('attr3'), ..…

> [@pokoli](#):
>
> This behaviour was the same on older series.

We had no ploblems with this model in Tryton 4.x.

---

<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:** [February 26, 2020, 3:50pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/4 "2020-02-26T15:50:18Z")

</div>

The problem is when the user tries to save some data. As rule of dump you should add read only access to the table\_query models, so the buttons are disabled on the client, no operation is performed and the error is not raised.

On the other hand, if you want to save data for the model you should override the create/write and delete methods to save the data somewhere.

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 26, 2020, 5:36pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/5 "2020-02-26T17:36:01Z")

</div>

> [@pokoli](#):
>
> The problem is when the user tries to save some data.

Our users can not save data in this model.

> [@pokoli](#):
>
> As rule of dump you should add read only access to the table\_query models, so the buttons are disabled on the client, no operation is performed and the error is not raised.

This does not work in our case. The error still occurs.

Our model was implemented following the example of `babi module` that you recommended.

```
query = {'attr1': value1, 'attr2': value2, 'attr3': value3, ...}
query, = Query.create([query])
query.validate_model()
query.create_keywords()

```

The error is caused by the line:

```
query, = Query.create([query])

```

---

<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:** [February 26, 2020, 6:20pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/6 "2020-02-26T18:20:16Z")

</div>

> [@bell](#):
>
> The error is caused by the line:
> 
> ```auto
> query, = Query.create([query])
> 
> ```

Right, because you create a record from a table that does not exist.  
Why are you creating this record?

P.S: It is dificult to understand the full picture without the full code.

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 26, 2020, 6:36pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/7 "2020-02-26T18:36:04Z")

</div>

> [@pokoli](#):
>
> Why are you creating this record?

I tried to do as in your example.  
Actually, I do not need this record. Ultimately, records will be generated using table\_query.  
I just need to dynamically create a new instance of the class `Query`. How can I do that?

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 26, 2020, 6:45pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/8 "2020-02-26T18:45:48Z")

</div>

> [@pokoli](#):
>
> Right, because you create a record from a table that does not exist.

I wonder why this worked in Tryton 4.x?

---

<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:** [February 26, 2020, 6:57pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/9 "2020-02-26T18:57:20Z")

</div>

> [@bell](#):
>
> I just need to dynamically create a new instance of the class `Query` . How can I do that?

Why you need to do so? If you have a table query all the instances will be directly returned from an sql query.

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 27, 2020, 10:43am UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/10 "2020-02-27T10:43:16Z")

</div>

OK. In [babi module](https://bitbucket.org/nantic/trytond-babi/src/5a0d62cc709e8bf5e26fa56524249409d92e69e3/babi.py) and in our module, a class is dynamically created, not an instance.  
This is done using [register\_class](https://bitbucket.org/nantic/trytond-babi/src/5a0d62cc709e8bf5e26fa56524249409d92e69e3/babi.py#lines-283) function in [validate\_model](https://bitbucket.org/nantic/trytond-babi/src/5a0d62cc709e8bf5e26fa56524249409d92e69e3/babi.py#lines-1134) method.  
But when a view is displayed in the client, an instance of this class is also created.  
What should I do instead of `Query.create()` calling?

---

<div class="post-metadata">

**Author:** ![bell](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bell](https://discuss.tryton.org/u/bell)\
**Post date:** [February 28, 2020, 2:39pm UTC](https://discuss.tryton.org/t/notimplementederror-on-table-query/2377/11 "2020-02-28T14:39:57Z")

</div>

The problem was resolved by replacing the lines:

```
query = {'attr1': value1, 'attr2': value2, 'attr3': value3, ...}
query, = Query.create([query])

```

with the line:

`query = Query()`

But `query` instance is only needed to call `validate_model` method that dynamically creates a new class.  
Is there a simpler solution?
