Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntArray size=64 support #609

Open
polmonso opened this issue Sep 1, 2021 · 6 comments
Open

IntArray size=64 support #609

polmonso opened this issue Sep 1, 2021 · 6 comments

Comments

@polmonso
Copy link

polmonso commented Sep 1, 2021

I couldn't find in the documentation what is the size of the integers when using IntArray data type. How could I tell pony to use size=64 (bigint) ?

Using postgresql.

@sashaaero
Copy link
Member

@polmonso
Copy link
Author

polmonso commented Sep 1, 2021

@sashaaero this is for int, I am referring to IntArray. It should be something like Required(IntArray, size=64) but it is not accepted syntax. intarray support was introduced on version 0.7.7. See https://docs.ponyorm.org/array.html

@pprovart
Copy link

pprovart commented Jan 16, 2022

Telegram ID's are large numbers and require 8byte Integer handling. An array of these ID's needs IntArray to be able to handle them.

So, I have a problem where a postgresql database for these IDs, has a TABLE created with one of the Columns having a TYPE of Integer[] .
administrators | integer[]

The Python Code Defining the Class for this table , has a line like below which uses Pony.

administrators = Required(IntArray, default=[])

So Far so good, where the ID values coming from Telegram are within the normal Int Size.

But When a large 'administrator id, ( from Tele gram) is added.. it throws an error with 'Integer out of Range' error from SQL.
Which is because IntArray uses default Python 3.10 Int , so maybe the Database is assuming a normal size of Integer and not a larger size.

Does IntArray support large Integer numbers eg size=64?

( I spent hours debugging , testing to come to this conclusion.)

@superantim
Copy link

Telegram ID's are large numbers and require 8byte Integer handling. An array of these ID's needs IntArray to be able to handle them.

So, I have a problem where a postgresql database for these IDs, has a TABLE created with one of the Columns having a TYPE of Integer[] . administrators | integer[]

The Python Code Defining the Class for this table , has a line like below which uses Pony.

administrators = Required(IntArray, default=[])

So Far so good, where the ID values coming from Telegram are within the normal Int Size.

But When a large 'administrator id, ( from Tele gram) is added.. it throws an error with 'Integer out of Range' error from SQL. Which is because IntArray uses default Python 3.10 Int , so maybe the Database is assuming a normal size of Integer and not a larger size.

Does IntArray support large Integer numbers eg size=64?

( I spent hours debugging , testing to come to this conclusion.)

i have same problem, how can you fix this? can't use id = PrimaryKey(int, size=64) for User(db.Entity)

@pprovart
Copy link

In the Class definition that is used to create the tables i had to add an sql_type = "bigint[]" command for it to accept the TG ids in the POSTGRES SQL Database.

class Chat(db.Entity):
administrators = Required(IntArray, default=[], sql_type="bigint[]")

I didnt have a problem with the Class User: definition as per below.. i kept this the same.
class User(db.Entity):
id = PrimaryKey(int, size=64)

@superantim
Copy link

superantim commented Sep 28, 2022

In the Class definition that is used to create the tables i had to add an sql_type = "bigint[]" command for it to accept the TG ids in the POSTGRES SQL Database.

class Chat(db.Entity): administrators = Required(IntArray, default=[], sql_type="bigint[]")

I didnt have a problem with the Class User: definition as per below.. i kept this the same. class User(db.Entity): id = PrimaryKey(int, size=64)

my problem is ValueError: Value 5701537852 of attr User.id is greater than the maximum allowed value 2147483647
i try to id = PrimaryKey(int, sql_type="bigint") but not work, pls help me
my code using pyrogram 1.4.6 and pony 0.7.14

async def from_pyrogram(tg_user: Union[types.User, types.Message,
types.InlineQuery, types.ChosenInlineResult,
types.CallbackQuery]) -> Union['User', None]:
with db_session:
if not isinstance(tg_user, types.User):
tg_user = tg_user.from_user

        if not tg_user:
            return None

        user_id = tg_user.id
        first_name = tg_user.first_name
        last_name = tg_user.last_name or ''
        username = tg_user.username or ''
        language = languages.get_nearest(tg_user.language_code)
        dc_id = tg_user.dc_id
        is_bot = tg_user.is_bot

        db_user: User = User.get(id=tg_user.id)

        if not db_user:
            db_user = User(id=user_id,
                           first_name=first_name,
                           last_name=last_name,
                           username=username,
                           language=language,
                           is_bot=is_bot,
                           dc_id=dc_id)

            db_user.is_first_use = True
        else:
            db_user.is_active = True
            db_user.first_name = first_name
            db_user.last_name = last_name
            db_user.username = username
            db_user.dc_id = dc_id or db_user.dc_id

            db_user.is_first_use = False

        db_user.tg = tg_user

    return db_user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants