adarshj322 / KV_Store

File based Key-Value Store implemented using mmap and sqlitedict
0 stars 0 forks source link

wired issue #1

Open wanghaisheng opened 2 years ago

wanghaisheng commented 2 years ago

1.


try:
        inst = create_inst('fastlane')

except:
        print('dict not exist')
else:
        print('dict exist')
        inst.create("fastlane_category1", {'noteable':'','hot':'','gold':'','mostview-six':'','mostview-year':''})
        # inst.commit()
for key, value in inst.iteritems():
     print(key, value)
dict exist
fastlane_category1 {"noteable": "", "hot": "", "gold": "", "mostview-six": 
"", "mostview-year": ""}

2.

try:
        inst = create_inst('fastlane')

except:
        print('dict not exist')
else:
        print('dict exist')
#         inst.create("fastlane_category1", {'noteable':'','hot':'','gold':'','mostview-six':'','mostview-year':''})
#         # inst.commit()
# for key, value in inst.iteritems():
#      print(key, value)
try:
    key = 'fastlane-category1'
    (inst.read(key))
except:
    print('key not exist',inst.read(key))
else:
    print(555,inst.read(key))
  File "..\aivideo\kvstore\sqlitedict_kv\keystore.py", line 83, in read    
    val = self.__dict[key]
  File "D:\Program Files\anaconda3\lib\site-packages\sqlitedict.py", line 244, in __getitem__
    raise KeyError(key)
KeyError: 'fastlane-category1'

During handling of the above exception, another exception occurred:        

Traceback (most recent call last):
  File "test-fastlane.py", line 46, in <module>
    (inst.read(key))
  File "..\aivideo\kvstore\sqlitedict_kv\keystore.py", line 90, in read    
    raise KeyError("error: given key does not exist in database. Please enter a valid key") #raising a key error
KeyError: 'error: given key does not exist in database. Please enter a valid key'
    def read(self,key) -> dict:
        for key, value in self.__dict.iteritems():
            # print(key, value)   
            pass     
        with self.__lock:
            try:
                val = self.__dict[key]
                # print(222,val)
            except:

            # if key not in self.__dict:
                # print(111,self.__dict)

                raise KeyError("error: given key does not exist in database. Please enter a valid key") #raising a key error
            else:
                mydict = json.loads(self.__dict[key])

                return mydict
wanghaisheng commented 2 years ago

3.when i change

    def read(self,key) -> dict:
        for key, value in self.__dict.iteritems():
            print(key, value)        
        with self.__lock:
            try:
                val = self.__dict[key]
                print(222,val)
            except:

            # if key not in self.__dict:
                print(111,self.__dict)

                raise KeyError("error: given key does not exist in database. Please enter a valid key") #raising a key error
            else:
                mydict = json.loads(self.__dict[key])

                return mydict

output

dict exist
fastlane_category1 {"noteable": "", "hot": "", "gold": "", "mostview-six": 
"", "mostview-year": ""}
222 {"noteable": "", "hot": "", "gold": "", "mostview-six": "", "mostview-year": ""}
fastlane_category1 {"noteable": "", "hot": "", "gold": "", "mostview-six": 
"", "mostview-year": ""}
222 {"noteable": "", "hot": "", "gold": "", "mostview-six": "", "mostview-year": ""}
555 {'noteable': '', 'hot': '', 'gold': '', 'mostview-six': '', 'mostview-year': ''}
wanghaisheng commented 2 years ago

if comment

        for key, value in self.__dict.iteritems():
            # print(key, value)
            pass   

error shows up again with key not exist