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

Initial support for file metadata. #38

Merged
merged 1 commit into from
Aug 29, 2023
Merged

Initial support for file metadata. #38

merged 1 commit into from
Aug 29, 2023

Conversation

jgadling
Copy link
Collaborator

No description provided.

@@ -50,6 +51,33 @@ async def get_entities(
return result.scalars().all()


async def get_files(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the File table doesn't have its own owner/collection id's so we have to tweak the fetch code to filter fields from the related Entity type.

if type(related_model) == db.File:
load_method = get_files
else:
load_method = get_entities
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Switch between entity/file loaders. We might want a prettier way to break this up (maybe a config map?) in the future.

@@ -125,6 +158,22 @@ async def resolve_entity(
return resolve_entity


def get_file_loader(sql_model, gql_type):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

again, very slightly different code path than Entities

producing_run_id = Column(Integer, nullable=True)
owner_user_id = Column(Integer, nullable=False)
collection_id = Column(Integer, nullable=False)
producing_run_id: Mapped[uuid.UUID] = mapped_column(Integer, nullable=True)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently SQLAlchemy wants us to use mapped_column from now on:
https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#orm-declarative-models

@@ -602,6 +602,7 @@ def convert(type_: Any) -> Any:

if make_interface:
mapped_type = strawberry.interface(type_)
self.mapped_interfaces[type_.__name__] = mapped_type
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There's a bug in the mapper where it'd loop over all currently-unmapped fields and try to map them, until the list of unmapped fields is empty. The mapper keeps track of mapped_types and mapped_interfaces and adds types to the mapped_types dict ... and doesn't have any code in it to ever update mapped_interfaces so the app goes into an infinite loop at map-time.

I'm not sure if this is a perfect fix, but it seems like an improvement.

Copy link
Contributor

@robertaboukhalil robertaboukhalil left a comment

Choose a reason for hiding this comment

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

Nice!

@jgadling jgadling merged commit c37ad46 into main Aug 29, 2023
2 checks passed
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