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

StringAdapter not useable #358

Open
Blindfreddy opened this issue Oct 20, 2024 · 1 comment
Open

StringAdapter not useable #358

Blindfreddy opened this issue Oct 20, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@Blindfreddy
Copy link

The class StringAdapter in module casbin.persist.adapters.string_adapter does not appear to be useable because of a missing import statement in casbin.persist.adapters.__init__.py.

Steps to reproduce:

  1. install casbin
  2. run python interpreter
>>> import casbin.persist as p
>>> dir(p.adapters)
['FileAdapter', 'FilteredAdapter', 'FilteredFileAdapter', 'UpdateAdapter', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'asyncio', 'file_adapter', 'filtered_file_adapter']
>>> sa = p.adapters.StringAdapter("foo")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'casbin.persist.adapters' has no attribute 'StringAdapter'

Note that there is no class StringAdapter despite the presence of the module string_adapter.py

Fix
Edit casbin.persist.adapters.__init__.py, adding the import statement for string_adapers.py and adding it to the __all__ variable

# Copyright 2021 The casbin Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .string_adapter import StringAdapter
from .file_adapter import FileAdapter
from .filtered_file_adapter import FilteredFileAdapter
from ..update_adapter import UpdateAdapter

# alias import for backwards compatibility
FilteredAdapter = FilteredFileAdapter

__all__ = ["StringAdapter", "FileAdapter", "FilteredFileAdapter", "FilteredAdapter", "UpdateAdapter"]

Now it works:

>>> import casbin.persist as p
>>> dir(p)
['Adapter', 'BatchAdapter', 'FileAdapter', 'FilteredAdapter', 'FilteredFileAdapter', 'StringAdapter', 'UpdateAdapter', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'adapter', 'adapter_filtered', 'adapters', 'batch_adapter', 'load_policy_line', 'update_adapter']
>>> sa = p.StringAdapter("foo")
>>> sa
<casbin.persist.adapters.string_adapter.StringAdapter object at 0x10266b740>
@casbin-bot
Copy link
Member

@techoner @Nekotoxin

@casbin-bot casbin-bot added the enhancement New feature or request label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants