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

allow_client_generated_ids ignored in POST #72

Closed
frip opened this issue Aug 5, 2020 · 6 comments
Closed

allow_client_generated_ids ignored in POST #72

frip opened this issue Aug 5, 2020 · 6 comments

Comments

@frip
Copy link

frip commented Aug 5, 2020

Thank you for a great library that is saving me tons of time!

I have a problem using allow_client_generated_ids on one of my model-classes: Unless I add a line in safrs/base.py:_s_post() I get an exception claiming that my "client generated id" (the one I needed to set myself) is None. - I think it was incorrectly removed without checking the truth of cls.allow_client_generated_ids.

My solution is to modify the beginning of _s_post():

        if getattr(cls, "allow_client_generated_ids", False) is False:
            for col_name in cls.id_type.column_names:
                ...

(After this change I still needed to make sure that the class hat a GET as well as a POST-method (since it could be accessed via a relationship I thought I could get away without the GET), but then everything worked like a charm! :-)

@thomaxxl
Copy link
Owner

thomaxxl commented Aug 5, 2020

Hi,

Thanks for letting me know!

@frip
Copy link
Author

frip commented Aug 5, 2020

Thank you for the fast response!

I don't fully understand b3512db, but doesn't it imply that the id must also be called 'id'? (...which may or may not be the case when allow_client_generated_ids is True.) In my experience cls.id_type.column_names is a more accurate description of where the ids sit - in my case it was two, and neither was called 'id', so I'm afraid I'll still have a problem after your fix.

@thomaxxl
Copy link
Owner

thomaxxl commented Aug 5, 2020

Hi,

I should've read your report better. Anyway, I'll look into it again later this week.

@thomaxxl thomaxxl reopened this Aug 5, 2020
@frip
Copy link
Author

frip commented Aug 5, 2020

Thanks for reopening the issue!

Here is my model (built on the example/mini_app.py)

class User(SAFRSBase, db.Model):
    """
        description: User description
    """
    __tablename__ = "Users"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String)
    email = db.Column(db.String)
    others= db.relationship('UserOthers')
    others.http_methods = []


class UserOthers(SAFRSBase, db.Model):
    """
        description: description of UserOthers, e.g. list of some other instances accessible by the user.
    """
    __tablename__ = "UsersOthers"
    allow_client_generated_ids = True
    http_methods = ['GET', 'POST', 'DELETE']
    user_id = db.Column(db.Integer, db.ForeignKey('Users.id'), primary_key=True)
    other_id = db.Column(db.Integer, primary_key=True, autoincrement=False)

@thomaxxl
Copy link
Owner

thomaxxl commented Aug 6, 2020

Hi,

Can you check if e61742c works for you?

(The "id" in the POST swagger will be ignored because you supply the PKs in the attributes)

@frip
Copy link
Author

frip commented Aug 6, 2020

Yes, that works for me!
Thank you very much!! :-)

@thomaxxl thomaxxl closed this as completed Aug 6, 2020
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

2 participants