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

✨ Make field's description interpret as column's comment #1335

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

eumiro
Copy link

@eumiro eumiro commented Mar 29, 2025

I have fields with description attributes I'd like to use as comments on columns in Postgresql tables.

All tests in sqlmodel use sqlite that does not support column comments. So my test in this PR does not work. What would be the best way to test it for Postgres (and other RDBMs supporting column comments)?

When I locally replace the sqlite:// with a proper Postgresql connect string to my local database, the test passes.

There's #1293, but also without working test.

@iloveitaly
Copy link

iloveitaly commented Mar 31, 2025

Great minds think alike :)

#1293

@eumiro
Copy link
Author

eumiro commented Apr 1, 2025

So in the meantime I patched the current version of SQLModel and it works for Postgres as expected:


def patch_get_column_from_field():
    original_get_column_from_field = sqlmodel.main.get_column_from_field

    def patched_get_column_from_field(field: typing.Any) -> sqlmodel.Column:
        column = original_get_column_from_field(field)
        if hasattr(field, "description"):
            column.comment = field.description
        return column

    sqlmodel.main.get_column_from_field = patched_get_column_from_field

@iloveitaly
Copy link

Yeah, I have a similar patch implemented in this project: https://github.com/iloveitaly/activemodel

Supports table-level comments as well.

@svlandeg svlandeg changed the title Make field's description interpret as column's comment ✨ Make field's description interpret as column's comment Apr 4, 2025
@svlandeg svlandeg added the feature New feature or request label Apr 4, 2025
Copy link
Member

@svlandeg svlandeg left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the contribution! I'll put this PR in draft as long as the test suite is failing 🙏

@svlandeg svlandeg marked this pull request as draft April 4, 2025 08:04
@eumiro
Copy link
Author

eumiro commented Apr 4, 2025

@svlandeg The test suite will be falling until we find a way how to add postgresql functionality to the test suite.

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

Successfully merging this pull request may close these issues.

3 participants