Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to construct query #122

Closed
viperfx opened this issue Dec 27, 2012 · 5 comments
Closed

Unable to construct query #122

viperfx opened this issue Dec 27, 2012 · 5 comments

Comments

@viperfx
Copy link

viperfx commented Dec 27, 2012

{
"message": "Unable to construct query"
}

That is the message I receive when accessing the API.

Here is what I have in my app.py

class Media(db.Model):
    __tablename__ = 'media'

    media_id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.Unicode)
    link_addr = db.Column(db.Unicode)
    media_link = db.Column(db.Unicode)
    meta_data = db.relationship('Meta', backref=db.backref('media'), uselist=False)

class Meta(db.Model):
    __tablename__ = 'meta'

    id = db.Column(db.Integer, primary_key=True)
    media_id = db.Column(db.Integer, db.ForeignKey('media.media_id'))
    album_name = db.Column(db.Unicode)
    artists = db.Column(db.Unicode)
    song_name = db.Column(db.Unicode)
    gs_album_id = db.Column(db.Integer)
    gs_artist_id = db.Column(db.Integer)
    gs_song_id = db.Column(db.Integer)
    gs_url = db.Column(db.Unicode)

manager = flask.ext.restless.APIManager(app, flask_sqlalchemy_db=db)

manager.create_api(Media, methods=['GET'])
manager.create_api(Meta, methods=['GET', 'POST'])

also tried this which is a one to many join, even though I dont really need one. (This one worked before with roughly the same data but now it does not also work - giving same message).

    meta = db.relationship('Meta', backref=db.backref('media', lazy='joined'))

I am not sure what has changed in my data or env to make it output such an error so please I would appreciate some help with fixing this.

Is there any debug options so I can see whats happening?

@judywawira
Copy link

did you get a solution to this? I have the same problem

@sk3w
Copy link

sk3w commented Jan 14, 2013

I'm getting the same error for even some of the basic examples from the docs (ex. https://flask-restless.readthedocs.org/en/latest/quickstart.html), using python 2.7 and the following packages in a virtualenv (all dependencies from "pip install flask-restless"):

Flask==0.9
Flask-Restless==0.8.0
Flask-SQLAlchemy==0.16
Jinja2==2.6
SQLAlchemy==0.8.0b2
Werkzeug==0.8.3
python-dateutil==1.5
wsgiref==0.1.2

The issue goes away if you remove the "backref" option from the sqlalchemy relationship() call.

@sk3w
Copy link

sk3w commented Jan 15, 2013

I was able to fix my issues by downgrading to sqlalchemy 0.7.9.

@jfinkels
Copy link
Owner

Thanks @sk3w --- it seems something has changed in SQLAlchemy between version 0.7.9 and 0.8.0b2 that is causing some issue. I'll look into it.

@jfinkels
Copy link
Owner

This should be fixed now, by 995754a (and the related 90f24b5). Now, if you are getting errors, it should be because you described your models incorrectly. Here's the issue.

According to the warning in this section of the SQLAlchemy documentation, dynamic relationship can only be used for one-to-many relationships, not many-to-one relationships. I was using SQLAlchemy incorrectly in my examples and test cases. In version 0.7.9, SQLAlchemy provided no warning or exception. In version 0.8.0b2, SQLAlchemy raises an exception if you try to use a dynamic relationship loader for the wrong kind of relationship.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants