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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:19+00:00 2026-06-08T09:23:19+00:00

I have written the following function using sqlalchemy (my underlying db is PostgreSQL 8.4).

  • 0

I have written the following function using sqlalchemy (my underlying db is PostgreSQL 8.4).
I have the following schema:

CREATE TABLE temporary_data_key (
                        id                          SERIAL PRIMARY KEY,
                        key                         VARCHAR(36) NOT NULL
                        );
CREATE UNIQUE INDEX idxu_temp_data_nm ON temporary_data_key (key);


CREATE TABLE temporary_data (
                        key_id                      INTEGER REFERENCES temporary_data_key(id) ON UPDATE CASCADE ON DELETE RESTRICT NOT NULL,
                        id_value                    INTEGER CHECK (id_value > 0) NOT NULL
                        );

I expect the function to clean up after itself (i.e. remove the generated key in temporary_table_key table) if an error occurs – for some reason, the table is not been cleared when an exception occurs.

Here is the function:

def storeIdsInTemporaryTable(dbinfo, id_list):
    conn = dbinfo['db_connection']
    metadata = dbinfo['metadata']
    tableinfo = Table('temporary_data', metadata, autoload=True)
    datarows = []

    temp_dbinfo = {'db_connection': conn, 'table': tableinfo, 'datarows': datarows }

    guid = genutils.getGUID()

    sql = "INSERT INTO temporary_data_key (key) VALUES ('{0}') RETURNING id".format(guid)
    key_id = executeSQLonDbConnection(temp_dbinfo, sql, return_field='id')

    for id_value in id_list:
        datarows.append( { 'key_id': key_id, 'id_value': id_value } )

    try:
        insertToDb(temp_dbinfo)
    except Exception as e:
        print 'ERROR:',e
        guid = None # to indicate an error occured
        if key_id:
            conn.execute("DELETE FROM temporary_data_key WHERE key='{0}'".format(key_id))

    return guid

Can anyone spot why the function is not cleaning up the temporary_data key as part of exception handling?

  • 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-08T09:23:20+00:00Added an answer on June 8, 2026 at 9:23 am

    I found the solution.

    The last line should be:

    if key_id:
        conn.execute("DELETE FROM temporary_data_key WHERE key='{0}'".format(guid))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following function: -- Gets stats for all markets CREATE OR
I have written the following query using the Aggregate function SUM. SELECT D.PODetailID, SUM(D.AcceptedQty)
I have written the following function.. and executed using WinHugs teneven = [x |
I have written the following function but it's isn't returning anything when I run
I have written the following algorithm in order to evaluate a function in MatLab
I have written the following code: #include <iostream> using namespace std; template <class T>
Why it is not allowed to overload = using friend function? I have written
I have written the following code using node.js and riak-js . I have a
I have written the following function meant to update a student in my database:
I have the following function written to randomly pick a file from a directory.

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.