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

Data viewing fixes #4

Merged
merged 4 commits into from
Jul 1, 2024
Merged

Conversation

ScriptSlayer0
Copy link
Contributor

I have fixed this error with the modification I have made, because every time you displayed the treeview you got an error message that doesn't appear anymore. But now I don't know how to fix the following.
Captura de pantalla 2024-06-24 124536
(Using the test file):
Captura de pantalla 2024-06-24 220113

@HarbingerOfFire
Copy link
Owner

Hi @Unaiperezdiaz, i like the idea of making the HDF5 handler as a single class, but the other parts of the code would need to be corrected to handle that code before any those updates can be published. Also, can I get a copy of your test file than you're using to get that error with BivitattusView? I will check it out and see if i can trace it.

@ScriptSlayer0
Copy link
Contributor Author

This file is from the same module "BDB_io.py".
test.zip
I hope you can trace the problem.
:)

@HarbingerOfFire
Copy link
Owner

it looks like you ran the output file from BDB_io.py through BivitattusView.py (onward 'BV'), but BV is setup to accept a very specific format of the text. Try running the example file ex_auto_commit.py to see if you get the same error with BV. Also, the output of BDB_io is just a tester to see if the code above works, not if it's compatible with the outside code. The code in BivitattusDB.py, BDB_metadata.py, and BDB_tb.py so that they run correctly with the HDF5Handler class.

@ScriptSlayer0
Copy link
Contributor Author

I used the example file ex_auto_commit.py .
And the output was:
Traceback (most recent call last): File "d:\github\bivittatusDB\src\BivitattusDB\ex_auto_commit.py", line 6, in <module> tb1 = test_db.make_table("table1", ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 44, in make_table return self.load_table(name) ^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 18, in load_table return table(self.database_name, table_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 12, in __init__ self.__read__() File "d:\github\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 33, in __read__ reader=io.read(self.database) ^^^^^^^ AttributeError: module 'BDB_io' has no attribute 'read' encrypting...
I'm trying to get a fix

@HarbingerOfFire
Copy link
Owner

Would you like to continue working on it, or should I give it a shot?

@ScriptSlayer0
Copy link
Contributor Author

I'm working on it, but I have found a strange file output executing ex_auto_commut.py
output.zip
All file with random numbers.

@HarbingerOfFire
Copy link
Owner

That's the encrypted database file. I found out on other projects that converting the encrypted text to hexadecimal decreases the risk of corruption or mis-understood directive when it comes to read/sending files. The key should be the password you set when initializing the test database

@ScriptSlayer0
Copy link
Contributor Author

After the commit this is the output:

Password for test: 
decrypting...
Error reading the database:  module 'BDB_io' has no attribute 'read'
No data to show.
encrypting...

@HarbingerOfFire
Copy link
Owner

When you restructered BDB.io into a class, the other files can't find the functions to read and write correctly. You got to change the read/write/edit functions in the other files so they can read the right code. For example, in BDB_tb.py:
This:

def __edit__(self):
       '''Change data in database table. Used in the __save__ method'''
       editor=io.edit(self.database)
       new_data=json.dumps([self.columns]+self.data)
       editor.edit_table(self.table_name, new_data)

would need to be:

def __edit__(self):
        '''Change data in database table. Used in the __save__ method'''
        editor=io.HDF5Handler(self.database)
        new_data=json.dumps([self.columns]+self.data)
        editor.edit_table(self.table_name, new_data)

@ScriptSlayer0
Copy link
Contributor Author

Password for test:
decrypting...
Error reading the table table1: Unable to synchronously open file (file signature not found)
No data to show.
encrypting...

@HarbingerOfFire
Copy link
Owner

it looks like the data is never decompressed when reading the table:

Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list
Traceback (most recent call last):
  File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BivittatusDB.py", line 19, in load_table
    return table(self.database_name, table_name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 13, in __init__
    self.__read__()
  File "c:\Users\malac\Code\Python\Bivattus\bivittatusDB\src\BivitattusDB\BDB_tb.py", line 47, in __read__
    self.data = json.loads(table_data)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\malac\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not list

@ScriptSlayer0
Copy link
Contributor Author

umh... this is new when I create a new DB using the example code:
Password for test: Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list Traceback (most recent call last): File "d:\github\bivittatusDB\src\BivitattusDB\ex_auto_commit.py", line 11, in <module> tb1 @ bdb.ON ~~~~^~~~~~~~ TypeError: unsupported operand type(s) for @: 'NoneType' and 'bool' encrypting...

@HarbingerOfFire
Copy link
Owner

Yeah, I expanded the first error:
Error loading table table1 from database test: the JSON object must be str, bytes or bytearray, not list
and ditched the second.

@ScriptSlayer0
Copy link
Contributor Author

ScriptSlayer0 commented Jun 30, 2024

Why don't we check the JSON before dumping it?
I think that's the best way to understand what's going on.

Because if this JSON has a problem, which we can't see because it is compressed and encrypted, we can't know if there will be more problems or not.

@HarbingerOfFire
Copy link
Owner

What I think is happening is that when we reload the JSON when reading the data into a newly loaded table, it's not getting decoded and decompressed before being converted back to obj format.

@ScriptSlayer0
Copy link
Contributor Author

Sometimes it appears: An error occurred: Non-hexadecimal digit found

@HarbingerOfFire
Copy link
Owner

Yeah, that's unhexlify trying to decode the encryption, but it's finding bytes instead of hexadecimal

@HarbingerOfFire
Copy link
Owner

So, I found there was a clause to decode and decompress during the read process, and then we were trying to do it again afterwards, which threw an error. I fixed that in both the bdb_tb and bdb_metadata tables, but I've came across another error while reading a already created table, which I am working on currently.

@HarbingerOfFire HarbingerOfFire merged commit 5863101 into HarbingerOfFire:main Jul 1, 2024
@HarbingerOfFire
Copy link
Owner

Ok... didn't mean to merge it... but hopefully you can find the error of why it's having problems reopening the file

@HarbingerOfFire
Copy link
Owner

Also, I just want to let you know, I'm working on a C code that can replace the use of HDF5 files, so this issue may just solve itself.

@ScriptSlayer0
Copy link
Contributor Author

I have solved the problem to be able to display the ex_auto_commit.py data.

@HarbingerOfFire
Copy link
Owner

what about ex_use_table.py

@ScriptSlayer0
Copy link
Contributor Author

ScriptSlayer0 commented Jul 1, 2024

Withex_use_table.py throws:
Error reading the table Table1: "Unable to synchronously open object (object 'Table1' doesn't exist)"

@HarbingerOfFire
Copy link
Owner

Yeah, I was getting the same error, I though I'd give it to you to try. Right now I have it committed with this error (by accident) so hopefully we can fix it.

quick tip. you can expand the traceback by importing traceback and adding the line print(traceback.format_exc()) inside the except clause that is causing the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants