RobertCraigie / prisma-client-py

Prisma Client Python is an auto-generated and fully type-safe database client designed for ease of use
https://prisma-client-py.readthedocs.io
Apache License 2.0
1.85k stars 81 forks source link

Not working with non-ASCII paths in Windows #943

Open Keiishu opened 5 months ago

Keiishu commented 5 months ago

Bug description

When working on Windows, using the latest version of the module, neither prisma generate throws an error when there's a non-ASCII character in the path ; for example, a grave accent in the name of a folder.

Traceback ``` Traceback (most recent call last): File "C:\Users\Martin\Documents\Universit�\2023-2024\Cours\Q2\Technologies Web\Projet\.venv\Lib\site-packages\prisma\g enerator\generator.py", line 109, in run self._on_request(request) File "C:\Users\Martin\Documents\Universit�\2023-2024\Cours\Q2\Technologies Web\Projet\.venv\Lib\site-packages\prisma\g enerator\generator.py", line 162, in _on_request self.generate(data) File "C:\Users\Martin\Documents\Universit�\2023-2024\Cours\Q2\Technologies Web\Projet\.venv\Lib\site-packages\prisma\g enerator\generator.py", line 251, in generate shutil.copy(data.schema_path, packaged_schema) File "C:\Users\Martin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 419, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "C:\Users\Martin\AppData\Local\Programs\Python\Python311\Lib\shutil.py", line 256, in copyfile with open(src, 'rb') as fsrc: ^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Martin\\Documents\\Université\\2023-2024\\Cours\\Q2\ \Technologies Web\\Projet\\prisma\\schema.prisma' ```

Note the accent in the traceback. Tried in both PowerShell and classic CMD.

This behaviour does not appear on Linux at all.

I tried to debug it myself, because it's certainly a parsing somewhere that isn't working with UTF-8 consistently, but I didn't find what I was trying to find. Where should we look into?

EDIT: I tried to copy the project folder in my main user directory and prisma db push, and it worked, but it generated the client in the wrong path. It created a new folder alongside the one with a grave accent, and just put the client there. No "FileNotFoundError".

Console session (.venv) PS C:\Users\Martin\Ceci est un test\Projet> prisma db push Environment variables loaded from .env Prisma schema loaded from prisma\schema.prisma Datasource "db": MongoDB database "lte" at "lte.wmoyioi.mongodb.net" The database is already in sync with the Prisma schema. Running generate... - Prisma Client Python (v0.13.1) ✔ Generated Prisma Client Python (v0.13.1) to .\..\..\Documents\Universit�\2023-2024\Cours\Q2\Technologies Web\Projet\.v env\Lib\site-packages\prisma in 270ms

How to reproduce

  1. On Windows, create a virtual environment, using Python 3.11.3
  2. Install the latest prisma-client-py version with pip
  3. Create a dummy prisma/schema.prisma
  4. In the console, using PowerShell or CMD, execute prisma db push

Expected behavior

The prisma client isn't generated, and we are instead greeted with a FileNotFoundError error, and a new folder on the disk, with every non-ASCII character replaced with a symbol.

Environment & setup

prisma                : 5.11.0
@prisma/client        : Not found
Computed binaryTarget : windows
Operating System      : win32
Architecture          : x64
Node.js               : v20.12.2
Query Engine (Binary) : query-engine efd2449663b3d73d637ea1fd226bafbcf45b3102 (at ..\..\..\..\..\..\..\.cache\prisma-python\binaries\5.11.0\efd2449663b3d73d637ea1fd226bafbcf45b3102\node_modules\@prisma\engines\query-engine-windows.exe)
Schema Engine         : schema-engine-cli efd2449663b3d73d637ea1fd226bafbcf45b3102 (at ..\..\..\..\..\..\..\.cache\prisma-python\binaries\5.11.0\efd2449663b3d73d637ea1fd226bafbcf45b3102\node_modules\@prisma\engines\schema-engine-windows.exe)
Schema Wasm           : @prisma/prisma-schema-wasm 5.11.0-15.efd2449663b3d73d637ea1fd226bafbcf45b3102
Default Engines Hash  : efd2449663b3d73d637ea1fd226bafbcf45b3102
Studio                : 0.499.0
RobertCraigie commented 5 months ago

Thanks for the report, have you verified if the TypeScript client works for you?

Keiishu commented 5 months ago

Thanks for your answer. I just tried on a new project, with the TypeScript client, in a path containing an accent, and it works :

prisma db push ``` Prisma schema loaded from prisma\schema.prisma Datasource "db": SQLite database "database.db" at "file:database.db" SQLite database database.db created at file:database.db Your database is now in sync with your Prisma schema. Done in 81ms Running generate... (Use --skip-generate to skip the generators) added 1 package, and audited 722 packages in 7s 116 packages are looking for funding run `npm fund` for details found 0 vulnerabilities ✔ Generated Prisma Client (v5.13.0) to .\node_modules\@prisma\client in 106ms PS C:\Users\Martin\Documents\Université\Prisma Test\éé\Prisma Test> ```
prisma version ``` PS C:\Users\Martin\Documents\Université\Prisma Test\éé\Prisma Test> prisma version Environment variables loaded from .env prisma : 5.13.0 @prisma/client : 5.13.0 Computed binaryTarget : windows Operating System : win32 Architecture : x64 Node.js : v20.12.2 Query Engine (Node-API) : libquery-engine b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at node_modules\@prisma\engines\query_engine-windows.dll.node) Schema Engine : schema-engine-cli b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b (at node_modules\@prisma\engines\schema-engine-windows.exe) Schema Wasm : @prisma/prisma-schema-wasm 5.13.0-23.b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b Default Engines Hash : b9a39a7ee606c28e3455d0fd60e78c3ba82b1a2b Studio : 0.500.0 ```
Keiishu commented 5 months ago

FYI, I tried with the latest commit (with Prisma 5.13.0), and it didn't work either