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

feat(sqla_factory): added __set_association_proxy__ attribute #624

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

Conversation

nisemenov
Copy link

Description

  • an async context manager has been added in SQLAASyncPersistence class to prevent
...
raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

The garbage collector is trying to clean up non-checked-in connection <AdaptedConnection <asyncpg.connection.Connection
object>>, which will be terminated.  Please ensure that SQLAlchemy pooled connections are returned to the pool 
explicitly, either by calling ``close()`` or by using appropriate context managers to manage their lifecycle.

sys:1: SAWarning: The garbage collector is trying to clean up non-checked-in connection <AdaptedConnection 
<asyncpg.connection.Connection object>>, which will be terminated.  Please ensure that SQLAlchemy pooled connections are 
returned to the pool explicitly, either by calling ``close()`` or by using appropriate context managers to manage 
their lifecycle.
  • build_async and batch_async methods have been added to work with Coroutine type field and to send them to the event pool;
  • __set_association_proxy__ attribute has been added in SQLAlchemyFactory class to add AssociationProxy type fields in the result FieldMeta factory dict.

@nisemenov nisemenov requested a review from guacs as a code owner December 27, 2024 11:06
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/624

"""
data: dict[str, Any] = cls.process_kwargs(**kwargs)
for k, v in data.items():
if isinstance(v, Coroutine):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this behaviour generally used for other async methods or more specific to SQLA relationships? If specific to SQLA then should live within that factory

Copy link
Author

Choose a reason for hiding this comment

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

I should check a bit, but could suppose this is more specific for SQLAlchemy proxy. If this behaviour is only for the Alchemy, I'll try to think something and leave it within SQLAlchemy factory.

@@ -213,6 +218,23 @@ def get_model_fields(cls) -> list[FieldMeta]:
random=cls.__random__,
),
)
if cls.__set_association_proxy__:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice. Adding as a feature makes sense here. Can appropriate tests and documentation be added for this feature please?

Copy link
Author

@nisemenov nisemenov Dec 28, 2024

Choose a reason for hiding this comment

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

Thanks! Ok, I'd try to do that.

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