Skip to content

Error loading policy during instantiation #5

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

Closed
RinkAttendant6 opened this issue Jan 9, 2022 · 2 comments
Closed

Error loading policy during instantiation #5

RinkAttendant6 opened this issue Jan 9, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@RinkAttendant6
Copy link

I get this error when trying to instantiate the Enforcer class using this adapter:

TypeError:
Argument 1 passed to CasbinAdapter\DBAL\Adapter::fetch() must be an instance of Doctrine\DBAL\Result, instance of Doctrine\DBAL\Driver\PDOStatement given, called in /<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php on line 153

  at /<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php:495
  at CasbinAdapter\DBAL\Adapter->fetch(object(PDOStatement))
     (/<redacted>/vendor/casbin/dbal-adapter/src/Adapter.php:153)
  at CasbinAdapter\DBAL\Adapter->loadPolicy(object(Model))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:363)
  at Casbin\CoreEnforcer->loadPolicy()
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:223)
  at Casbin\CoreEnforcer->initWithModelAndAdapter(object(Model), object(Adapter))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:198)
  at Casbin\CoreEnforcer->initWithAdapter('/<redacted>/permission_model.conf', object(Adapter))
     (/<redacted>/vendor/casbin/casbin/src/CoreEnforcer.php:150)
  at Casbin\CoreEnforcer->__construct('/<redacted>/resources/permission_model.conf', object(Adapter))
     (/<redacted>/src/Utilities/Permission.php:52)

From the composer.json file in this library, Doctrine 2.9 and 3.0 are supported. I am using Doctrine 2.9.3.

Digging through the source code, it looks like the execute method from DBAL Query Builder (called on line 151 in Adapter.php) returns a ResultStatement rather than the expected Result object.

Passing an array of parameters instead of a Connection object in the constructor produces the same result. Am I doing something wrong?

@RinkAttendant6
Copy link
Author

I just noticed in the upgrade document for DBAL 3.x:

BC BREAK changes in fetching statement results

  1. The Statement interface no longer extends ResultStatement.
  2. The ResultStatement interface has been renamed to Result.
  3. Instead of returning bool, Statement::execute() now returns a Result that should be used for fetching the result data and metadata.

In this case I suppose the library isn't compatible with DBAL 2.x ☹️

@leeqvip leeqvip added the bug Something isn't working label Jan 10, 2022
leeqvip added a commit that referenced this issue Jan 10, 2022
@leeqvip
Copy link
Member

leeqvip commented Jan 10, 2022

@RinkAttendant6 It has been fixed in v2.3.1.

@leeqvip leeqvip closed this as completed Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants