#πŸ”’ passing around SQL alchemy models

6 messages Β· Page 1 of 1 (latest)

hidden berry
#

Is it uncommon to pass SQL alchemy models around, even after their data has been committed. For example let's say I want to select data in a function, I commit the session and return the model.

I was getting the "instance is not bound to a session" error even after explicitly expunging the model from the session.

Just trying to figure out best practices here.

Thanks

willow pastureBOT
#

@hidden berry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

earnest edge
#

I don't use SQLalchemy, but I do use Django, which has a (I think) similar ORM. With Django, my models are all classes in a module called "models", and I just treat them as globals -- wherever I need them, I from .. import models and then refer to e.g. models.Car and models.Road or whatever.

hidden berry
#

Yeah that's not quite what I mean, it's specific instances of the models that I'm returning from a function, which leads to the above error. I'll post an example in just a few, once I'm home from work

willow pastureBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.