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

The Archive Base Latest Questions

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

Edit I found the answer and it’s not related to how the model is

  • 0

Edit I found the answer and it’s not related to how the model is setup. I was trying to pass the request.form from flask to a function that actually creates the address. Apparently converting that to kwargs causes a problem. Manually specifying each of the arguments made everything work correctly.

I’m new to SQLAlchemy and things have been going pretty well so far but I’ve hit a problem and I’m completely stumped so I’m hoping someone here knows what i’m doing wrong!

I have an address model and i’m trying to select from it. The model looks like this:

class Address(Base):
    __tablename__ = 'address'

    id = Column(Integer, primary_key=True)
    comment = Column(String(255))
    address1 = Column(String(100))
    address2 = Column(String(100))
    city = Column(String(45))
    state = Column(String(2))
    zip = Column(String(5))
    zip4 = Column(String(4))
    lat = Column(Float)
    lon = Column(Float)

I’m trying to match elements of an address entered through my application to see if I can find the lat and longitude without geocoding. I’ve used filter_by in other queries that worked so I am trying the same thing here: (the address dict comes from post parameters to my application)

matched_address = session.query(Address).filter_by(
    address1=address['address1'],
    city=address['city'],
    state=address['state'],
    zip=address['zip']
).one()

Unfortunately this is failing with a SQL Error:

ProgrammingError: (ProgrammingError) (1064, 'You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right 
syntax to use near \') AND address.state = ("\'XX\'",) AND address.zip = 
("\'XXXXX\'",) AND address.city \' at line 3')

This looks very very ugly! Where are the extra () come from? I turned on echo=True in my call to create_engine() and it prints a query that seems correct (I tried it in the mysql client with no problems):

SELECT address.id AS address_id, address.comment AS address_comment, 
    address.address1 AS address_address1, address.address2 AS address_address2, 
    address.city AS address_city, address.state AS address_state, 
    address.zip AS address_zip, address.zip4 AS address_zip4, 
    address.lat AS address_lat, address.lon AS address_lon 
FROM address 
WHERE address.address1 = %s AND address.state = %s AND address.zip = %s AND 
    address.city = %s 
LIMIT %s

But the parameters it says it’s outputting seems a little odd, though I’m not sure if this is just the python object or if it’s really going to MySQL this way: (note the X characters are just replacements for my real address)

([u'1111 XXXXXX St'], [u'XX'], [u'XXXXX'], [u'XXXXX'], 1)

Just for fun I tried using filter() instead of filter_by() but I get the same errors:

matched_address = database.session.query(Address).filter(
    and_(Address.address1==address['address1'], Address.city==address['city'],    
    Address.state==address['state'],Address.zip==address['zip'])).one()

Sorry if this is a basic question. Thanks in advance for any help!

  • 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-08T22:19:13+00:00Added an answer on June 8, 2026 at 10:19 pm

    I found the answer and it’s not related to how the model is setup. I was trying to pass the request.form from flask to a function that actually creates the address. Apparently converting that to kwargs causes a problem. Manually specifying each of the arguments made everything work correctly.

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

Sidebar

Related Questions

FINAL EDIT: After following the answer from Darin Dimitrov, I have found that the
EDIT 23-06-2012 10:24 (CET) : Found the answer Take a look at the bottom
EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator .
Edit #2: i disabled my 404 page and the default not found page says
EDIT: Answer found! Thank you very much people, a lot of answers worked, I
Edit: found the answer here: Using Ember.js, how do I run some JS after
EDIT Found the answer. It's a logical error located at if(carry == 0 &&
Here is a hum-dinger of a problem that I have not found an answer
Edit: Found the answer, see my answer below. I was testing the waters with
* EDIT: I found the answer to the memory leak myself, and posted it

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.