tortoise / aerich

A database migrations tool for TortoiseORM, ready to production.
https://github.com/tortoise/aerich
Apache License 2.0
804 stars 90 forks source link

Pydantic validation error when inspecting DB #322

Open GoldenCorgo opened 10 months ago

GoldenCorgo commented 10 months ago

When inspecting db (after all migrations) getting this error:

Stack trace:


Traceback (most recent call last):
  File "/usr/local/bin/aerich", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/cli.py", line 265, in main
    cli()
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/decorators.py", line 33, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/cli.py", line 31, in wrapper
    loop.run_until_complete(f(*args, **kwargs))
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/cli.py", line 260, in inspectdb
    ret = await command.inspectdb(table)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/__init__.py", line 124, in inspectdb
    return await inspect.inspect()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/inspectdb/__init__.py", line 95, in inspect
    columns = await self.get_columns(table)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aerich/inspectdb/postgres.py", line 62, in get_columns
    Column(
  File "/usr/local/lib/python3.11/site-packages/pydantic/main.py", line 165, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(data, self_instance=__pydantic_self__)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Column
extra
  Field required [type=missing, input_value={'name': 'id', 'data_type...: False, 'index': False}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.3/v/missing

Libs:

Not sure which additional info to provide. All tables have custom names with Meta class, also I have 2 custom field types:


class NativeDatetimeField(Field[datetime.datetime], datetime.datetime):
    SQL_TYPE = "timestamp without time zone"

class NativeDatetimeFieldNow(Field[datetime.datetime], datetime.datetime):
    SQL_TYPE = "timestamp without time zone DEFAULT now()"

Any suggestions what could it be?

long2ice commented 10 months ago

Please try latest source code.

edimedia commented 7 months ago

Hi log2ice, you are right when you saying that we must latest source code but when i'm trying pip install aerich the latest version is 0.7.2, and the pydantic validation error persists, and when i'm checking the code on github i can see the problem is solved, and i think so, the author have to update the python (pypi) repository please.