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

set default None for user_module_prefix #1233

Closed
wants to merge 2 commits into from
Closed

set default None for user_module_prefix #1233

wants to merge 2 commits into from

Conversation

allmonday
Copy link
Contributor

@allmonday allmonday commented May 5, 2023

fix #1235
fix KeyError of prefix = autogen_context.opts["user_module_prefix"] in render.py

Description

I've made a small snippet to generate create_table ops for my models

def create_orm_migration(metadata):

    operations = []
    for table in metadata.tables.values():
        if table.name.startswith('meeting_note'):
            operations.append(
                ops.CreateTableOp.from_table(table)
            )
            for idx in table.indexes:
                operations.append(ops.CreateIndexOp.from_index(idx))

    print(autogenerate.render_python_code(
        ops.UpgradeOps(ops=operations),
        ), 
    )

and it raises KeyError because UUID is defined in other modules.

from portal.utils.db import UUID

Base = declarative_base()

class MeetingNotes(Base, CommonFieldsMixin):
    __tablename__ = 'meeting_note_notes'

    id = Column(UUID, primary_key=True, default=uuid.uuid1)
    date = Column(Date)
    duration = Column(Integer)
    category = Column(String(1024))
    type = Column(String())
    host_employee_number = Column(Integer)
    content = Column(Text(100000))
    title = Column(String(1024))
    agenda = Column(Text())

this happens in autogenerate.render:_user_autogenerate_prefix, first I attempt to change

prefix = autogen_context.opts["user_module_prefix"]
# to
prefix = autogen_context.opts.get("user_module_prefix")

after I review code around, I guess this is designed to use [] instead of .get(), so I follow the code style and add the default argument user_module_prefix into autogenerate.api:render_python_code

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

fix KeyError of `prefix = autogen_context.opts["user_module_prefix"]` in render.py
@CaselIT
Copy link
Member

CaselIT commented May 5, 2023

Hi,

Thanks for the PR. Can you also open an issue so we can properly create a changelog?

Thanks!

@CaselIT CaselIT requested a review from zzzeek May 5, 2023 21:30
@allmonday
Copy link
Contributor Author

Hi,
linked with #1235 ~

@CaselIT CaselIT requested a review from sqla-tester May 11, 2023 20:43
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of CaselIT to try to get revision 6fa3bc1 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 6fa3bc1: https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4609

@sqla-tester
Copy link
Collaborator

Gerrit review https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/4609 has been merged. Congratulations! :)

@allmonday allmonday deleted the patch-1 branch May 13, 2023 12:04
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

Successfully merging this pull request may close these issues.

prefix = autogen_context.opts["user_module_prefix"] raise KeyError
3 participants