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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:55:57+00:00 2026-05-11T21:55:57+00:00

I have a simple Invoices class with a Number attribute that has to be

  • 0

I have a simple “Invoices” class with a “Number” attribute that has to
be assigned by the application when the user saves an invoice. There
are some constraints:

1) the application is a (thin) client-server one, so whatever
assigns the number must look out for collisions
2) Invoices has a “version” attribute too, so I can’t use a simple
DBMS-level autoincrementing field

I’m trying to build this using a custom Type that would kick in every
time an invoice gets saved. Whenever process_bind_param is called with
a None value, it will call a singleton of some sort to determine the
number and avoid collisions. Is this a decent solution?
Anyway, I’m having a problem.. Here’s my custom Type:

class AutoIncrement(types.TypeDecorator):
   impl = types.Unicode

   def copy(self):
       return AutoIncrement()

   def process_bind_param(self, value, dialect):
       if not value:
           # Must find next autoincrement value
           value = "1" # Test value :)
       return value

My problem right now is that when I save an Invoice and AutoIncrement
sets “1” as value for its number, the Invoice instance doesn’t get
updated with the new number.. Is this expected? Am I missing
something?
Many thanks for your time!

(SQLA 0.5.3 on Python 2.6, using postgreSQL 8.3)

Edit: Michael Bayer told me that this behaviour is expected, since TypeDecorators don’t deal with default values.

  • 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-11T21:55:58+00:00Added an answer on May 11, 2026 at 9:55 pm

    Is there any particular reason you don’t just use a default= parameter in your column definition? (This can be an arbitrary Python callable).

    def generate_invoice_number():
        # special logic to generate a unique invoice number
    
    class Invoice(DeclarativeBase):
        __tablename__ = 'invoice'
        number = Column(Integer, unique=True, default=generate_invoice_number)
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a simple application. It tries to add a new entry
I am supposed to print an array of invoices to our clients. There is
Have simple Order - Item app. No cart. Need help with joined scopes for
ASP.NET MVC makes it really easy to create editing templates for simple, flat objects.
I have a requirement for B2B integration, I will reading flat table from dataset
So I found some great info on Autocomplete for Rails 3, it looks really
I have the following dataset, I want to select distinct rows. since the data
Pardon the length, please. Also, this is a completely hypothetical, off-the-cuff situation and code
I am using an ExtJS 3.0 grid and generate data from PHP using MySQL.
In my project I am using a table named Compensation like..... +--------------------------------------------------------------+ | Id

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.