-
Notifications
You must be signed in to change notification settings - Fork 282
🐛 Handles incomplete list-type #385
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
Conversation
for more information, see https://pre-commit.ci
sheinbergon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for your contribution. The result creates a conflicting import where sqlalchemy ARRAY and postgres dialect ARRAY, are imported. You need to adapt your code to make sure only one type surfaces
|
Thank you for your review. I'll implement the necessary changes tomorrow evening. |
|
Should have addressed all of the points.
Note: That the bug mentioned here seems to have been part of the code for a while, the tests just never checked for an import with the same name from some other module - probably because it just doesn't happen. |
sheinbergon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much, much better.
One small comment. We still need to solve the double import issue
Again, thank you for your efforts. The PR is much better. But, we cannot merge it while the dual |
I can certainly take another crack at it. Although I do think I would need some help on the dual It could very well be a "skill-issue" on my side, I'm not quite familiar with the code yet. |
Once you're done with the final fix suggested, let me know and I will take a look |
Done! Edit: Feel free to ping me when you've gotten closer to the double-array problem. I think the following test demonstrates the problem. # Fails because postgres_array adds a second ARRAY import
def test_table_with_arrays(generator: CodeGenerator) -> None:
_ = Table(
"with_items",
generator.metadata,
Column("id", INTEGER, primary_key=True),
Column("int_items_not_optional", ARRAY(INTEGER()), nullable=False),
Column("postgres_array", postgresql.ARRAY(INTEGER()), nullable=False),
Column("str_matrix", ARRAY(VARCHAR(), dimensions=2)),
)
validate_code(
generator.generate(),
"""\
from typing import Optional
from sqlalchemy import ARRAY, INTEGER, Integer, VARCHAR
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class WithItems(Base):
__tablename__ = 'with_items'
id: Mapped[int] = mapped_column(Integer, primary_key=True)
int_items_not_optional: Mapped[list[int]] = mapped_column(ARRAY(INTEGER()))
postgres_array: Mapped[list[int]] = mapped_column(ARRAY(INTEGER()))
str_matrix: Mapped[Optional[list[list[str]]]] = mapped_column(ARRAY(VARCHAR(), dimensions=2))
""",
) |
|
@
Maybe I'm not seeing things correctly, but after the recent iteration, I'm not seeing the double ARRAY import anymore. I'm also not seeing any misplaced fixes. @JoaquimEsteves am I missing anything? |
|
@agronholm this went some review iteration. I pretty much approve what's going in @JoaquimEsteves contribution. Please have another look |
agronholm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What bugs me is the inconsistency. We're now suddenly using list but only in this new code. If we switch to using the generic built-ins, we should do the switch everywhere. And why did you duplicate the column type rendering code?
IMO We can do it in another PR. I don't think adding changes unrelated to |
Co-authored-by: Alex Grönholm <[email protected]>
|
Hello, thanks for the second look.
I second the idea that adding more generic built-ins can be done in future PRs. For example, I didn't change the Optional because the I didn't re-use the The double array problem went away once I fixed the test data. Running my patch on a postgres DB with arrays didn't yield any double imports. |
Right, of course. But it seems to me like this should be an overrideable method in the generator then, |
|
Ahoy hoy, Renamed the local function from If there's anything else feel free to ping :) |
agronholm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @sheinbergon ?
|
@agronholm @JoaquimEsteves let's also document this change in |
Oh, right, that's still missing. |
|
How about: **3.?.?**
- Array types are no longer partially unknown.
I don't know which version - should I put |
Exactly that. I actually just pushed a PR template with just such instructions. |
Perhaps something like "Type annotations for |
|
Great, works for me. |
|
Grand - I'll wait for @sheinbergon to approve, feel free to merge at your convenience. |
sheinbergon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Closes #383
Note: I don't have a postgres DB to play with this patch - I'm kind of hopping that the tests are enough. I can report back tomorrow when I'm back at $WORK
Another thing I could do (since I have my hands in the dough) is to add an option to the cli that makes it so that we don't import
typing.List, we could very well get away with just usinglist[<attribute here>].Indeed
typing.Listhas been deprecated since python 3.9.I could also do the same for
Optionalbut maybe that's best left to some other PR.