Coder Social home page Coder Social logo

Comments (8)

raddevon avatar raddevon commented on August 20, 2024

Thanks for the kind words, @bepetersn! I'm glad flask-permissions is helpful to you.

class User(UserLoginMixin, UserPermissionMixin, db.Model):

I noticed this in your traceroute. This is just a hunch, but I wonder if sub-classing your db.Model with your User class could be the problem since Flask-Permission's UserMixin already inherits from that same class.

If you want to post your implementation somewhere, I'll play with it locally and see what I can figure out. If you just want to post a Gist instead, I'll look it over and see if I can find anything. You're also welcome to take a look at the full project the example in the documentation is pulled from. The additional context might be helpful.

from flask-permissions.

bepetersn avatar bepetersn commented on August 20, 2024

That's interesting, I hadn't considered that, but it makes sense that I shouldn't use both db.Model and your UserMixin. After dropping db.Model, I still get the NoForeignKeys error though, unless I do one of the two things above (I think now that the second one may be the wrong solution).

I will get back to you some more a bit later, and maybe take a look at your project.

from flask-permissions.

raddevon avatar raddevon commented on August 20, 2024

Definitely. I'd be curious to know what the UserLoginMixin is that you're inheriting from. I assumed UserPermissionMixin is Flask-Permissions' UserMixin. I wonder if the __mapper_args__ are being clobbered by that inheritance.

from flask-permissions.

bepetersn avatar bepetersn commented on August 20, 2024

It's Flask-Login's (see https://flask-login.readthedocs.org/en/latest) UserMixin object. Same name as your mixin, so I switched to using the from x import y as z syntax to import both of them. I checked their source code, it doesn't inherit from Model, it just adds methods to related to stuff like session management.

from flask-permissions.

raddevon avatar raddevon commented on August 20, 2024

Any progress on this, @bepetersn? If not, I'm happy to see if anything in your code jumps out at me if you have it up or would like to make it available somewhere. Can't make any promises, but I'm hoping I might be able to see something that would lead us to the issue.

Not trying to rush you, but I'm making sure you're not waiting on me. 😄

from flask-permissions.

bepetersn avatar bepetersn commented on August 20, 2024

Hey, so much later, I tried to throw together an example of this without making any assumptions, and still ended up getting this error: sqlalchemy.exc.NoForeignKeysError: Can't find any foreign key relationships between 'fp_user' and 'users'. Here's a repo, if you find time to point me in the right direction: https://github.com/bepetersn/flask-permissions-ex

from flask-permissions.

raddevon avatar raddevon commented on August 20, 2024

@bepetersn I haven't touched this in a while, but I believe your problem is because you change the table for your user class (see https://github.com/bepetersn/flask-permissions-ex/blob/master/ex/database.py#L21). I think that's breaking the relationships the extension needs.

from flask-permissions.

bepetersn avatar bepetersn commented on August 20, 2024

Hi @raddevon, thanks for your reply. I realized that my example was slightly different from yours. I not only included the __tablename__, but also a primary key id. With either one I got the same error mentioned above, but removing both fixed it.

I didn't understand before that that the user table was being defined by you as fp_user and mine was inheriting from it using Joined Table Inheritance. After I figured that out, things got easier. Thanks!

from flask-permissions.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.