Skip to content

Conversation

@wannaphong
Copy link
Member

We encountered a problem when updating to the new version. The old corpus database does not work with the new version. This pull request will fix the new version update problem.

@wannaphong wannaphong added the bug bugs in the library label Jun 26, 2020
@wannaphong wannaphong added this to the 2.2 milestone Jun 26, 2020
@pep8speaks
Copy link

pep8speaks commented Jun 26, 2020

Hello @wannaphong! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 99:80: E501 line too long (84 > 79 characters)
Line 142:80: E501 line too long (98 > 79 characters)
Line 144:80: E501 line too long (95 > 79 characters)

Comment last updated at 2020-06-27 05:23:25 UTC

@coveralls
Copy link

coveralls commented Jun 26, 2020

Coverage Status

Coverage decreased (-0.4%) to 95.01% when pulling ab74589 on fix-update-bug into 7f24af2 on dev.

@wannaphong wannaphong requested a review from bact June 26, 2020 09:39
@bact
Copy link
Member

bact commented Jun 26, 2020

ถ้าทำแบบนี้ เท่ากับว่า ทุกครั้งที่เรียก get_corpus_path() มันก็จะดาวน์โหลดใหม่ทุกครั้งปะครับ แม้จะมีไฟล์อยู่แล้วก็ตาม

อ๋อ ผมนึกออกละ ตัว "file" นี่คือมันเป็นชื่อ field จากรุ่นเก่าใช่ไหมครับ
ดังนั้น ตรงนี้ควรจะทำงานแค่ครั้งเดียว ใช่ไหม

@bact
Copy link
Member

bact commented Jun 26, 2020

What about a separated script that the user will run only once to update their corpus database?

@wannaphong
Copy link
Member Author

What about a separated script that the user will run only once to update their corpus database?

Yes.

@bact
Copy link
Member

bact commented Jun 26, 2020

btw, should we choose only one between "file_name" and "filename" ? now we have "file_name" in the local db and "filename" in db.json

@wannaphong
Copy link
Member Author

btw, should we choose only one between "file_name" and "filename" ? now we have "file_name" in the local db and "filename" in db.json

I think we should change it according to db.json. use "filename".

@wannaphong
Copy link
Member Author

I think if we can find a way to update db.json, we may not have to force re-download.

@wannaphong
Copy link
Member Author

I updated db.json and I changed file_name to filename.

print("Update Corpus...")
local_db = TinyDB(corpus_db_path())
item_all = local_db.all()
local_db.close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is better to use with to handle IO related to variable. To illustrate, if L100 is failed, local_db might not release the TinyDB resource. This is because the close command isn't executed because the program is failed at L100.

In this case, we should use

with TinyDB(...) as local_db:
    # do something.

See detailed explanation: https://stackoverflow.com/a/2738468.

# check if the corpus is in local catalog, download if not
corpus_db_detail = get_corpus_db_detail(name)
if not corpus_db_detail or not corpus_db_detail.get("file_name"):
if (corpus_db_detail.get("file_name") is not None or corpus_db_detail.get("file") is not None) and corpus_db_detail.get("filename") is None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition is quite hard to digest.

@wannaphong
Copy link
Member Author

@heytitle OK. I Fixed it.

@wannaphong wannaphong merged commit a158dd4 into dev Jun 27, 2020
@wannaphong wannaphong mentioned this pull request Jun 27, 2020
@bact bact deleted the fix-update-bug branch June 27, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug bugs in the library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants