Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Peewee value returns to its default after few seconds (BUG?)

This used to be my model:

db = SqliteDatabase(Settings.stats_conf_database_location)

class ActivityTracker(Model):
    date = DateField(unique=True)
    activity_time_curr = IntegerField(default=0)  # active seconds today
    activity_time_max = IntegerField()   # max active seconds today

    class Meta:
        database = db

I added:

blocked = BooleanField(default=False)

as a 4th parameter

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and migrate code:

db.create_tables([ActivityTracker], safe=True)
# migration
table_name = ActivityTracker._meta.name
db_columns_dict = db.get_columns(table_name)
db_columns_name_list = [column.name for column in db_columns_dict]
updated_column = ActivityTracker.blocked
updated_column_name = ActivityTracker.blocked.name
if updated_column_name not in db_columns_name_list:
    migrator = SqliteMigrator(db)
    migrate(
        migrator.add_column(table_name, updated_column_name, updated_column)
    )

So far so good.
I started to something strange once I update the blocked value:

ActivityTracker.update(blocked=True).where(ActivityTracker.date == datetime.today()).execute()

enter image description here

The value gets updated:
enter image description here

ISSUE: After 10 – 30 seconds the value gets set back to 0

enter image description here

Not a single line of code is executed.
This happens over all my 600+ processes across 4 different Windows PCs.

I know also see the activity time current changed back to some old version.

ISSUE BREADCRUMBS:

        activity_tracker_obj, created = ActivityTracker.get_or_create(date=_datetime.date.today(),
                                                                   defaults={'activity_time_curr': 0,
                                                                             'activity_time_max': max_working_seconds_today,
                                                                             'blocked': False})
        InstaPyLimits.activity_tracker_obj = activity_tracker_obj  # store today pointer in db

    def update_daily_activity(time):
        #print(f'adding today time {time}')
        activity_tracker = InstaPyLimits.activity_tracker_obj
        new_time = activity_tracker.activity_time_curr + time
        activity_tracker.activity_time_curr = new_time
        activity_tracker.save()

The activity_tracker.save() in async thread is reseting it to 0, why ?
Why is it taken old value ? should I refetch it from database ?

>Solution :

OK ISSUES IS:
That a pointer to the database is not refreshing automatically, it pointing to local data in memory so holding old data.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading