tortoise / tortoise/tortoise-orm

Unable to use array_append function.

Open
#762 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

I tried making a custom function. Array Append

class ArrayAppend(Function):
    def __init__(self, field: str, value: typing.Any) -> None:
        super().__init__("ARRAY_APPEND", F(field), value)
# Use Case
record = await Items.filter(id=5).first()
record.orders= ArrayAppend("orders", 1234)
await record.save()

This raises a error, which is pretty self explanatory but I am not getting why this is happening..

tortoise.exceptions.OperationalError: function array_append(bigint[], integer) does not exist
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Edit:

It magically worked, when I tried, str(int) instead of integer directly.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files or tests. Start by reproducing the custom ArrayAppend call against PostgreSQL and trace how Function arguments are typed; done means the expected array_append usage is supported or the limitation is documented and covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.