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 8628281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:29:49+00:00 2026-06-12T08:29:49+00:00

I want to get a row from mysql database, then modiy some fields and

  • 0

I want to get a row from mysql database, then modiy some fields and commit. Before I commit, updating this row shoud be forbidden. so I use with_lockmode(‘update’). I use the
following RoutingSession and I find it use Slave to do this query. But I want to do this query using Master, what should I do in get_bind???

class RoutingSession(Session):
    def get_bind(self, mapper=None, clause=None):
        if self._flushing:

            return engines['master']
        else:
            return engines['slave']

row = session.query(SomeTable).filter(SomeTable.id = 1).with_lockmode('update').one
row.somefield = 'newcontent'
session.commit()
  • 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-06-12T08:29:51+00:00Added an answer on June 12, 2026 at 8:29 am

    I’m assuming you got this recipe from my blog post at Django-style Database Routers in SQLAlchemy. If you look in the section “manual access” you’ll see a recipe for when you need to explicitly point the routing session to a certain node:

    class RoutingSession(Session):
    
        def get_bind(self, mapper=None, clause=None ):
            if self._name:
                return engines[self._name]
            elif mapper and issubclass(mapper.class_, OtherBase):
                return engines['other']
            elif self._flushing:
                return engines['master']
            else:
                return engines[
                        random.choice(['slave1','slave2'])
                    ]
    
        _name = None
        def using_bind(self, name):
            s = RoutingSession()
            vars(s).update(vars(self))
            s._name = name
            return s
    

    Then you just do your operation with that bind explicitly:

    m1 = Session().using_bind("master").query(Model1).first()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get the contents from a row in the database and compare
I randomly get a row from a mysql-database using php (ugly random, I know).
I want to know how to get a specific row from a table in
I want to get values from a row with the largest certain value (in
I have a PHP server script that SELECTs some data from a MySQL database.
Goal: To retrieve a single record (row) from a MySQL database for a user
I want to select a row from mysql which matches a specific id. I
I have done this before and for some reason I just can't get it
I want to update every row on a specific column in a mySql database.
I'm using this query to getresults from my database: MATCH(`Text2`) AGAINST ('$s') I want

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.