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

Use select(list_schema) when available #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

udiNur
Copy link

@udiNur udiNur commented Feb 14, 2023

When there is schema_list that used another table e.g.

class BestColor(BestColorBase, table=True):
    id: int = Field(default=None, primary_key=True)
    songs: List["Song"] = Relationship(
        back_populates="best_color",
        sa_relationship_kwargs={'lazy': 'joined'}
    )



class Song(SongBase, table=True):
    id: int = Field(default=None, primary_key=True)
    secret: str = Field(default=None, sa_column_kwargs={"nullable": True})
    password: str = Field(default=None, sa_column_kwargs={"nullable": True})
    artists: List["Artist"] = Relationship(
        back_populates="songs", link_model=SongArtistLink,
        sa_relationship_kwargs={'lazy': 'selectin'}
    )
    best_color_id: Optional[int] = Field(
        default=None, foreign_key="bestcolor.id",

    )
    best_color: Optional[BestColor] = Relationship(
        back_populates="songs",
        sa_relationship_kwargs={'lazy': 'selectin'}
    )

the data will not populate on the route_list, in case of best_color is not optional it will cause an error.

with my PR it will actually fetch according to the schema_list.

Please ask me to implement it any other way, or if you prefer fix it yourself.

P.S. I've tried to run the test myself but I had a few problems.

  1. When running a poetry-related command, I got an error of missing the [tool.poetry] section on pyproject.toml
(fastapi-sqlmodel-crud-py3.7) udin@ttys006:~/fastapi-sqlmodel-crud$ poetry add
[tool.poetry] section not found in /Users/udin//fastapi-sqlmodel-crud/pyproject.toml
  1. After fixing it, I got E ModuleNotFoundError: No module named 'sqlalchemy_database'
  2. After trying to add it via poetry add I got that:
The current project's Python requirement (>=2.7,<2.8 || >=3.4) is not compatible with some of the required packages Python requirement:
  - sqlalchemy-database requires Python >=3.7, so it will not be satisfied for Python >=2.7,<2.8 || >=3.4,<3.7

Because no versions of sqlalchemy-database match >0.1.0,<0.2.0
 and sqlalchemy-database (0.1.0) requires Python >=3.7, sqlalchemy-database is forbidden.
So, because streampay-backend depends on sqlalchemy-database (^0.1.0), version solving failed.

please let me know if I can help in any way or if I missing anything

@amisadmin
Copy link
Owner

yehuda a added 2 commits February 14, 2023 15:37
# Conflicts:
#	fastapi_sqlmodel_crud/_sqlmodel.py
@udiNur
Copy link
Author

udiNur commented Feb 14, 2023

Thank you for your quick response, I just merge your changes on my PR.
Now when I trying to run pdm install I'm still getting the error that based on what I mentioned earlier:

(fastapi-sqlmodel-crud-py3.7) udin@ttys015:~/fastapi-sqlmodel-crud$ pdm install
Lock file does not exist
Updating the lock file...
Inside an active virtualenv /Users/udin/Library/Caches/pypoetry/virtualenvs/fastapi-sqlmodel-crud-tKTMUsk5-py3.7, reusing it.
🔒 Lock failed
Unable to find a resolution because the following dependencies don't work on all Python versions in the range of the project's `requires-python`: >=3.6.1.
  python>=3.7 (from <Candidate sqlalchemy-database@0.1.0 from https://pypi.org/simple/sqlalchemy-database/>)
A possible solution is to change the value of `requires-python` in pyproject.toml to >=3.7.
See /var/folders/h1/lv56zn2d4jd3347zprf6g75w0000gn/T/pdm-lock-bwaug43t.log for detailed debug log.
[ResolutionImpossible]: Unable to find a resolution
Add '-v' to see the detailed traceback

If I changing the pyproject.toml requires-python to = ">=3.7" it working ok

@amisadmin
Copy link
Owner

  • I'm not sure about the environmental installation problems you're having. because I developed the library in a fastapi-amis-admin environment.
  • The changes you submit should be fine, but the fields in schema_list can be very complex, and it needs to support fields in other models. This change could have a big impact on the fastapi-amis-admin project, and there is currently no way to add it to the main branch.
  • If it is perfectly compatible with fastapi-amis-admin, I would be happy to merge it.

@udiNur
Copy link
Author

udiNur commented Feb 14, 2023

  • installation problem: in order to replicate them just clone the repo and run pdm install

I found that the repo mixed a lot with fastapi-amis-admin, for example, the test that I just fix, so IDK if you want it to be a "standalone repo" or not.
If I will run the tests onfastapi-amis-admin with my change it will be enough to check it? do you prefer me to do something else in order to check it?

from fastapi_amis_admin.models import Field
from fastapi_sqlmodel_crud import SQLModelCrud
from fastapi_sqlmodel_crud.parser import LabelField, PropertyField
# from fastapi_amis_admin.models import Field # what should I do here?
Copy link
Author

@udiNur udiNur Feb 14, 2023

Choose a reason for hiding this comment

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

what should I do here?

Copy link
Owner

Choose a reason for hiding this comment

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

what should I do here?

from sqlmodel import Field

@amisadmin
Copy link
Owner

  • installation problem: in order to replicate them just clone the repo and run pdm install

I found that the repo mixed a lot with fastapi-amis-admin, for example, the test that I just fix, so IDK if you want it to be a "standalone repo" or not. If I will run the tests onfastapi-amis-admin with my change it will be enough to check it? do you prefer me to do something else in order to check it?

Yes, you can clone the fastapi-amis admin repository for development and testing. Use pdm install -d to install the development environment.

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.

2 participants