7. Interview Questions- ORM Extensions
1. What is the purpose of SQLAlchemy ORM extensions?
2. What is hybrid_property used for in SQLAlchemy?
hybrid_property used for in SQLAlchemy?3. How do you define a hybrid_property?
hybrid_property?from sqlalchemy.ext.hybrid import hybrid_property
class User(Base):
first_name = Column(String)
last_name = Column(String)
@hybrid_property
def full_name(self):
return f"{self.first_name} {self.last_name}"4. What is association_proxy and when would you use it?
association_proxy and when would you use it?5. How does association_proxy improve developer experience?
association_proxy improve developer experience?6. What is the purpose of mutable extension in SQLAlchemy?
mutable extension in SQLAlchemy?7. How do you use a mutable dictionary in SQLAlchemy?
8. Can mutable be used with custom user-defined types?
mutable be used with custom user-defined types?9. What problem does MutableDict or MutableList solve?
MutableDict or MutableList solve?10. What is the purpose of async_session extension in SQLAlchemy 2.0?
async_session extension in SQLAlchemy 2.0?11. How do you create an AsyncSession?
AsyncSession?12. What is the difference between Session and AsyncSession?
Session and AsyncSession?13. Can AsyncSession be used with standard SQLAlchemy models?
AsyncSession be used with standard SQLAlchemy models?14. What is hybrid_method in SQLAlchemy?
hybrid_method in SQLAlchemy?15. How do you define a hybrid_method?
hybrid_method?16. What is the main use case of declarative_mixin in extensions?
declarative_mixin in extensions?17. How is declarative_mixin different from a regular Python mixin?
declarative_mixin different from a regular Python mixin?18. Can association_proxy work with lists or scalar values?
association_proxy work with lists or scalar values?19. What is a limitation of association_proxy?
association_proxy?20. Can hybrid properties be used in filters or joins?
21. Can hybrid_property include a class-level expression for SQL querying?
hybrid_property include a class-level expression for SQL querying?22. What’s the benefit of using a hybrid_property over a regular Python property in ORM?
hybrid_property over a regular Python property in ORM?23. What are the two components of a hybrid_property?
hybrid_property?24. How can you make a hybrid_property writable?
hybrid_property writable?25. Can you use a hybrid_method inside a SQL filter()?
hybrid_method inside a SQL filter()?26. What is create_proxied_attribute() used for in association proxies?
create_proxied_attribute() used for in association proxies?27. What happens if a proxy target in association_proxy is None?
association_proxy is None?28. How do you define a custom creator in association_proxy?
association_proxy?29. What types of structures can be tracked using the mutable extension?
mutable extension?30. What method must a custom mutable class implement?
31. Can mutable objects be used with PostgreSQL JSONB columns?
JSONB columns?32. How do you persist a change made to a dictionary without reassigning it?
33. What does MutableList.coerce() do?
MutableList.coerce() do?34. Can you combine hybrid properties with association proxies?
35. What exception is raised if an AsyncSession is used improperly without await?
AsyncSession is used improperly without await?36. What is the async equivalent of session.execute(select(...))?
session.execute(select(...))?37. How do you configure AsyncSession with a sessionmaker?
AsyncSession with a sessionmaker?38. What does expire_on_commit=False help with in AsyncSession?
expire_on_commit=False help with in AsyncSession?39. Can you use association_proxy in async ORM queries?
association_proxy in async ORM queries?40. How do you ensure lazy-loaded relationships don’t block event loops in async ORM?
41. Can hybrid_property be used with a @property decorator at the same time?
hybrid_property be used with a @property decorator at the same time?42. How do you query using a hybrid_property that has a class-level .expression()?
hybrid_property that has a class-level .expression()?43. How do you use MutableComposite?
MutableComposite?44. What is the difference between MutableList and ARRAY in PostgreSQL?
MutableList and ARRAY in PostgreSQL?45. Why is it important to use as_mutable() when working with mutable extensions?
as_mutable() when working with mutable extensions?46. Can you use association_proxy to access an attribute on a nested relationship?
association_proxy to access an attribute on a nested relationship?47. What happens if a hybrid property is accessed on the class but lacks .expression()?
.expression()?48. What is async_sessionmaker() and how does it differ from sessionmaker()?
async_sessionmaker() and how does it differ from sessionmaker()?49. What is the purpose of __composite_values__() in a MutableComposite?
__composite_values__() in a MutableComposite?50. Can you use selectinload() with AsyncSession to preload relationships?
selectinload() with AsyncSession to preload relationships?Last updated