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

Bug: NameError: name 'BigInteger' is not defined #3737

Closed
1 of 4 tasks
cbdiesse opened this issue Sep 14, 2024 · 3 comments
Closed
1 of 4 tasks

Bug: NameError: name 'BigInteger' is not defined #3737

cbdiesse opened this issue Sep 14, 2024 · 3 comments
Labels
Bug 🐛 This is something that is not working as expected

Comments

@cbdiesse
Copy link

cbdiesse commented Sep 14, 2024

Description

subclassing

class BigIntAuditBase(CommonTableAttributes, BigIntPrimaryKey, AuditColumns, DeclarativeBase):
    """Base for declarative models with BigInt primary keys and audit columns."""

    registry = orm_registry

cause the mentioned error

URL to code causing the issue

No response

MCVE

# Your MCVE code here
class User(BigIntAuditBase):
    __tablename__ = "core.user_account"
    __table_args__ = {"comment": "User accounts for application access"}
    __pii_columns__ = {"name", "email", "avatar_url"}

    email: Mapped[str] = mapped_column(unique=True, index=True, nullable=False)
    name: Mapped[str | None] = mapped_column(nullable=True, default=None)

Steps to reproduce

1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

(.venv) cbdiesse@MacStudodeKasor appsys % make migrations
ATTENTION: This operation will create a new database migration for any defined models changes.
Migration message: DB Migration 1024-09-14
Using Litestar app from env: 'app.asgi:app'
Loading environment configuration from .env
Traceback (most recent call last):
  File "/Users/cbdiesse/work/kas3/appsys/.venv/bin/app", line 8, in <module>
    sys.exit(run_cli())
             ^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/kaspy/app/__main__.py", line 26, in run_cli
    run_litestar_cli()
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/__main__.py", line 6, in run_cli
    litestar_group()
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/rich_click/rich_command.py", line 151, in main
    with self.make_context(prog_name, args, **extra) as ctx:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 224, in make_context
    self._prepare(ctx)
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 206, in _prepare
    env = ctx.obj = LitestarEnv.from_env(ctx.params.get("app_path"), ctx.params.get("app_dir"))
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 112, in from_env
    loaded_app = _load_app_from_path(app_path)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/cli/_utils.py", line 277, in _load_app_from_path
    module = importlib.import_module(module_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/Users/cbdiesse/work/kas3/appsys/kaspy/app/asgi.py", line 52, in <module>
    app = create_app()
          ^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/kaspy/app/asgi.py", line 33, in create_app
    return Litestar(
           ^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/app.py", line 486, in __init__
    self.register(route_handler)
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/app.py", line 687, in register
    route_handler.on_registration(self)
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/http_handlers/base.py", line 561, in on_registration
    super().on_registration(app)
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/base.py", line 538, in on_registration
    self._validate_handler_function()
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/http_handlers/base.py", line 572, in _validate_handler_function
    super()._validate_handler_function()
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/base.py", line 549, in _validate_handler_function
    self.parsed_data_field is not None
    ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/base.py", line 241, in parsed_data_field
    self._parsed_data_field = self.parsed_fn_signature.parameters.get("data")
                              ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/handlers/base.py", line 226, in parsed_fn_signature
    self._parsed_fn_signature = ParsedSignature.from_fn(
                                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/utils/signature.py", line 215, in from_fn
    fn_type_hints = get_fn_type_hints(fn, namespace=signature_namespace)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/litestar/utils/signature.py", line 168, in get_fn_type_hints
    hints = get_type_hints(fn_to_inspect, globalns=namespace, include_extras=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cbdiesse/work/kas3/appsys/.venv/lib/python3.12/site-packages/typing_extensions.py", line 1230, in get_type_hints
    hint = typing.get_type_hints(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 2310, in get_type_hints
    hints[name] = _eval_type(value, globalns, localns, type_params)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 415, in _eval_type
    return t._evaluate(globalns, localns, type_params, recursive_guard=recursive_guard)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.5/Frameworks/Python.framework/Versions/3.12/lib/python3.12/typing.py", line 947, in _evaluate
    eval(self.__forward_code__, globalns, localns),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 1, in <module>
NameError: name 'BigInteger' is not defined
make: *** [migrations] Error 1

Litestar Version

litestar 2.11.0

Platform

  • Linux
  • Mac
  • Windows
  • Other (Please specify in the description above)

Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@cbdiesse cbdiesse added the Bug 🐛 This is something that is not working as expected label Sep 14, 2024
@provinzkraut provinzkraut changed the title Bug: <title>NameError: name 'BigInteger' is not defined Bug: NameError: name 'BigInteger' is not defined Sep 14, 2024
@provinzkraut
Copy link
Member

This works for me. Can you provide a self-contained example that's able to reproduce the error?

@cbdiesse
Copy link
Author

cbdiesse commented Sep 15, 2024

Hi @provinzkraut,
Thanks for taking a look to this issue.
Th simple way to reproduce this error is to change the User model in litestar-fullstack sample repository,
from class User(UUIDAuditBase): ...
to class User(BigIntAuditBase): ...
and adjust or remove code related to User relationships.
I am using that example as startup of my project.
When i run the script: make migrations, I have errors as show in the log.

Maybe the error is from the super classes BigIntPrimaryKey which map BigIntIdentity with no
import of BigInteger

BigIntIdentity = BigInteger().with_variant(Integer, "sqlite")
"""A ``BigInteger`` variant that reverts to an ``Integer`` for unsupported variants."""

Just a speculation from me ... I am newbie in python but I have strong background in others languages (Java, C/C++, etc., ). Mathematics background is making me catchup fast with python, but the operations side is very tricky and have some trouble configuring vscode which is new for me.
My project is an ERP backend with python modules at the core distributed micro services and java components as clients of those micro services.

regards

@cofin
Copy link
Member

cofin commented Sep 22, 2024

@cbdiesse I'm going to close this as it's mainly related to Advanced Alchemy. I think you have a similar issue over on that project. Can we move the discussion over there for other updates?

Feel free to open a new issue (or reopen) if necessary though.

@cofin cofin closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

No branches or pull requests

3 participants