Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PermissionError on Windows while inserting many items #102

Description

@difhel

Describe the bug

PermissionError: [Errno 13] Permission denied: 'filename.json' is thrown when a large number of items are inserted by the for loop. Many elements output the obscure "utf-8" string but appear in the file. A file access error occurs on some item. I called this several times and each time I got an error on inserting a different element. Therefore, I am sure that this is a critical bug related to filelock.
Code:

second = """20053197
359237977
... some data (100+ strings)
736041598
610442490""".split("\n")
for e in second:
    print(e)
    SUBSCRIPTIONS.add({"vkid": int(e)})

Output:

...
utf-8
747262594
utf-8
285519977
utf-8
696637496
utf-8
659376205
Traceback (most recent call last):
  File "c:\Users\Mark\Desktop\vkg\vkgid.py", line 236, in <module>
    SUBSCRIPTIONS.add({"vkid": int(e)})
  File "C:\Users\Mark\AppData\Local\Programs\Python\Python311\Lib\site-packages\pysondb\db.py", line 91, in add
    with open(self.filename, "r+", encoding='utf-8') as db_file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [Errno 13] Permission denied: 'subscriptions.json'

I also find it strange to output "utf-8" everywhere. It's like when something throws a KeyError, you catch it and output like in this example:

a = {"foo": None} # some test dict
try:
    print(a["bar"])
except Exception as e:
    print(e)
# returns "bar"

How to reproduce

Use Windows 10 and pysondb==1.6.7 (the latest?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions