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

Soalan tentang pemasangan samudra: module 'samudra.models' has no attribute 'TABLES' #21

Open
Thaza-Kun opened this issue Nov 1, 2022 Discussed in #20 · 0 comments
Assignees
Labels
🐞 Pepijat Ada sesuatu yang tidak berfungsi dengan baik

Comments

@Thaza-Kun
Copy link
Collaborator

Discussed in #20

Originally posted by mshumayl October 25, 2022
Saya mendapati ralat ketika cuba memasang samudra. Saya kemukakan ralat ini dalam bahagian 'discussion' ini untuk memahami lebih lanjut tentang pemasangan dan di mana saya tersalah. Saya pasti saya terlepas pandang sesuatu yang jelas, jadi saya amat menghargai sebarang penunjuk dari tuan/puan.

Terima kasih terlebih dahulu atas penerangan dan masa tuan/puan.

Penerangan ralat

Ralat AttributeError: module 'samudra.models' has no attribute 'TABLES' muncul setelah membuat beberapa perubahan untuk memasang cabang master samudra (commit 79b6a76ff7d46814a9c9992a9d4f82fe7cee7048). Berikut merupakan perubahan yang dilakukan.

Cara untuk ulang ralat

  1. Salin repo menggunakan $ git clone https://github.com/Thaza-Kun/samudra.git samudra seperti diperincikan dalam Pemasangan.
  2. Masuk ke dalam folder samudra seperti yang diperincikan dalam Pemasangan.
  3. Dapatkan semua keperluan project menggunakan poetry seperti yang diperincikan dalam Pemasangan.
  4. Sediakan fail .env di ROOT seperti yang diperincikan, dan meletakkan ACCESS_TOKEN_EXPIRE_MINUTES kepada 10 minit:
# ./.env

# Buat masa sekarang ada tiga enjin: SQLite, MySQL, dan CockroachDB.
# SQLite sesuai untuk aplikasi lokal dan hanya satu pengguna.
# Yang lain memerlukan pelayan
ENGINE = SQLite

# Yang ini adalah nilai yang diperlukan untuk daftar masuk pelayan DB
# (Tidak perlu kalau pilih enjin SQLite)
DATABASE_USERNAME = 
DATABASE_PASSWORD = 

# Maklumat pelayan DB
# (Tidak perlu kalau pilih enjin SQLite)
DATABASE_NAME = 
DATABASE_HOST = 
DATABASE_PORT = 
DATABASE_OPTIONS = 

# Tempoh masa pengguna dibenarkan log masuk (dalam sukatan minit)
# (Wajib walaupun pilih enjin SQLite)
ACCESS_TOKEN_EXPIRE_MINUTES = 10
  1. Mulakan pelayan dari ROOT menggunakan $ poetry run python ./samudra/serve.py, dan ralat dibawah akan muncul:
Traceback (most recent call last):
  File "Z:\Noconda\samudra\samudra\serve.py", line 12, in <module>
    from samudra.server.setup import check_tables
  File "Z:\Noconda\samudra\samudra\server\__init__.py", line 4, in <module>
    from .routes import lemmas, auth, golongan_kata
  File "Z:\Noconda\samudra\samudra\server\routes\lemmas.py", line 7, in <module>
    from samudra.server.dependencies import get_db
  File "Z:\Noconda\samudra\samudra\server\dependencies.py", line 4, in <module>
    from samudra.server.setup import SERVER_DATABASE
  File "Z:\Noconda\samudra\samudra\server\setup.py", line 7, in <module>
    from samudra.conf.database.core import ENGINE
ImportError: cannot import name 'ENGINE' from 'samudra.conf.database.core' (.\samudra\samudra\conf\database\core.py)
  1. Untuk menghilangkan ralat ini, saya cuma nyahkomen baris-baris (16 dan 17) berikut di \samudra\samudra\conf\database\core.py:
# ENGINE = settings.get("database").get("engine", None)
# DATABASE_NAME = settings.get("database").get("name", "samudra")
  1. Kemudian, setelah menjalankan $ poetry run python ./samudra/serve.py lagi, ralat kemudiannya akan muncul:
Traceback (most recent call last):
  File "Z:\Noconda\samudra\samudra\serve.py", line 12, in <module>
    from samudra.server.setup import check_tables
  File "Z:\Noconda\samudra\samudra\server\__init__.py", line 4, in <module>
    from .routes import lemmas, auth, golongan_kata
  File "Z:\Noconda\samudra\samudra\server\routes\lemmas.py", line 7, in <module>
    from samudra.server.dependencies import get_db
  File "Z:\Noconda\samudra\samudra\server\dependencies.py", line 4, in <module>
    from samudra.server.setup import SERVER_DATABASE
  File "Z:\Noconda\samudra\samudra\server\setup.py", line 11, in <module>
    SERVER_DATABASE: pw.Database = get_database(engine=DatabaseEngine[ENGINE])
TypeError: get_database() missing 1 required positional argument: 'db_name'
  1. Saya cuba dengan meletakkan argumen db_name dalam panggilan fungsi get_database tersebut di baris 11 dalam fail .\samudra\samudra\server\setup.py:
SERVER_DATABASE: pw.Database = get_database(engine=DatabaseEngine[ENGINE], db_name='samudra_local')
  1. Setelah menjalankan $ poetry run python ./samudra/serve.py, ralat seterusnya muncul:
Traceback (most recent call last):
  File "Z:\Noconda\samudra\samudra\serve.py", line 12, in <module>
    from samudra.server.setup import check_tables
  File "Z:\Noconda\samudra\samudra\server\__init__.py", line 4, in <module>
    from .routes import lemmas, auth, golongan_kata
  File "Z:\Noconda\samudra\samudra\server\routes\lemmas.py", line 7, in <module>
    from samudra.server.dependencies import get_db
  File "Z:\Noconda\samudra\samudra\server\dependencies.py", line 4, in <module>
    from samudra.server.setup import SERVER_DATABASE
  File "Z:\Noconda\samudra\samudra\server\setup.py", line 11, in <module>
    SERVER_DATABASE: pw.Database = get_database(engine=DatabaseEngine[ENGINE], db_name='samudra_local')
  File "Z:\Noconda\samudra\samudra\conf\database\core.py", line 36, in get_database
    return create_sqlite(folder=db_name, path=kwargs.pop("path"), **kwargs)
KeyError: 'path'
  1. Saya cuba dengan mewujudkan folder baru bernama site/local, dan meletakkan path ini kepada argumen path dalam panggilan fungsi get_database yang sama (baris 11):
SERVER_DATABASE: pw.Database = get_database(engine=DatabaseEngine[ENGINE], db_name='samudra_local', path=r'Z:\Noconda\samudra\site\local')
  1. Setelah menjalani $ poetry run python ./samudra/serve.py lagi sekali, sebuah README.md fail akan dijana di Z:\Noconda\samudra\site\local\samudra_local, dan kita tiba kepada ralat seperti di tajuk:
Traceback (most recent call last):
  File "Z:\Noconda\samudra\samudra\serve.py", line 40, in <module>
    check_tables(create_tables=True)
  File "Z:\Noconda\samudra\samudra\server\setup.py", line 26, in check_tables
    for TABLE in models.TABLES:
AttributeError: module 'samudra.models' has no attribute 'TABLES'

Berikut merupakan kandungan Z:\Noconda\samudra\site\local\samudra_local\README.md:

# Samudra_Local
Created using [samudra](https://github.com/samudradev/samudra)

Yang telah dicuba

  1. Saya cuba untuk tentukan pembolehubah senarai kosong TABLES dan JOIN_TABLES dalam \samudra\samudra\models\__init__.py, dan uvicorn akan mula melayan. Tetapi ini terlalu jelik sebagai penyelesaian, dan akan menyebabkan ralat 'circular reference' seperti berikut:
INFO:     Will watch for changes in these directories: ['Z:\\Noconda\\samudra']
INFO:uvicorn.error:Will watch for changes in these directories: ['Z:\\Noconda\\samudra']
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:uvicorn.error:Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)      
INFO:     Started reloader process [19260] using StatReload
INFO:uvicorn.error:Started reloader process [19260] using StatReload
Traceback (most recent call last):
  File "Z:\Noconda\samudra\samudra\conf\database\core.py", line 79, in create_sqlite
    base_path.mkdir(parents=True)
  File "Z:\Miniconda3\lib\pathlib.py", line 1312, in mkdir
    self._accessor.mkdir(self, mode)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'Z:\\Noconda\\samudra\\site\\local\\samudra_local'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "Z:\Miniconda3\lib\multiprocessing\spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "Z:\Miniconda3\lib\multiprocessing\spawn.py", line 125, in _main
    prepare(preparation_data)
  File "Z:\Miniconda3\lib\multiprocessing\spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "Z:\Miniconda3\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "Z:\Miniconda3\lib\runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "Z:\Miniconda3\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "Z:\Miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "Z:\Noconda\samudra\samudra\serve.py", line 12, in <module>
    from samudra.server.setup import check_tables
  File "Z:\Noconda\samudra\samudra\server\__init__.py", line 4, in <module>
    from .routes import lemmas, auth, golongan_kata
  File "Z:\Noconda\samudra\samudra\server\routes\lemmas.py", line 7, in <module>
    from samudra.server.dependencies import get_db
  File "Z:\Noconda\samudra\samudra\server\dependencies.py", line 4, in <module>
    from samudra.server.setup import SERVER_DATABASE
  File "Z:\Noconda\samudra\samudra\server\setup.py", line 11, in <module>
    SERVER_DATABASE: pw.Database = get_database(engine=DatabaseEngine[ENGINE], db_name='samudra_local', path=r'Z:\Noconda\samudra\site\local')
  File "Z:\Noconda\samudra\samudra\conf\database\core.py", line 36, in get_database
    return create_sqlite(folder=db_name, path=kwargs.pop("path"), **kwargs)
  File "Z:\Noconda\samudra\samudra\conf\database\core.py", line 88, in create_sqlite
    raise FileExistsError(
FileExistsError: The path `Z:\Noconda\samudra\site\local\samudra_local` is already occupied with something else. Consider using other folder.
  1. Saya cuba mewujudkan fail kosong Z:\Noconda\samudra\site\local\samudra_local.sqlite, dan ini juga tidak dapat menyelesaikan ralat ini.

Butiran lanjut

Jikalau tuan/puan perlukan butiran lanjut tentang ralat ini, boleh beritahu saya. Maaf terlebih dahulu jika saya terlepas pandang sesuatu yang jelas.

Terima kasih lagi sekali atas masa tuan/puan serta usaha tuan/puan membangunkan samudra.

@Thaza-Kun Thaza-Kun added the 🐞 Pepijat Ada sesuatu yang tidak berfungsi dengan baik label Nov 1, 2022
@Thaza-Kun Thaza-Kun self-assigned this Nov 1, 2022
mshumayl added a commit to mshumayl/samudra that referenced this issue Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Pepijat Ada sesuatu yang tidak berfungsi dengan baik
Projects
None yet
Development

No branches or pull requests

1 participant