Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6777345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:08:11+00:00 2026-05-26T16:08:11+00:00

I am using a relational database via SQLAlchemy. I want to spawn a job

  • 0

I am using a relational database via SQLAlchemy. I want to spawn a job that deals with databases using Celery. There is a code:

from sqlalchemy.orm.session import Session
from celery.task import task
from myapp.user import User

@task
def job(user):
    # job...
    session = Session.object_session(user)
    with user.begin():
        user.value = result_value

def ordinary_web_request_handler(uid):
    assert isinstance(session, Session)
    user = session.query(User).get(int(uid))
    # deals with user...
    job.delay(user)
    return response

I need to use a SQLAlchemy session in the delayed job, but there’s no session yet. How can I set a session into passed user entity?

There are ways I thought, but I am not sure which of these (or none of these) is the best practice:

  • Always pass only primary keys and retrieve new instances by the passed primary keys.
  • Set the session of the passed instances (but I don’t know how).
  • Do not use ORM in the delayed task.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:08:12+00:00Added an answer on May 26, 2026 at 4:08 pm

    You should be able to initiate your session with the worker signals: http://celery.readthedocs.org/en/latest/userguide/signals.html#worker-signals

    If you use a singleton-like pattern to make sure you always have a session available in that thread than everything should work just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access a legacy relational database via ActiveRecord and that database uses
I'm using Delphi to create an XML document from data in a relational database.
Please excuse any mistakes in terminology. In particular, I am using relational database terms.
I'm starting a new semester and for my class relational databases they are using
After using relational databases as back-end storage all my Windows programming life (currently .NET),
Coming from a relational database background, as I'm sure many others are, I'm looking
Imagine 2 tables in a relational database, e.g. Person and Billing. There is a
I need to implement a web app, but instead of using relational database I
In a C++ application that can use just about any relational database, what would
Strings are unbounded, but it seems every normal relational database requires that a column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.