Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed a bug in updating loan stats.

The library field was getting lost when the loan is updated. Fixed it by
retaining already existing fields.
  • Loading branch information...
commit ffd670585d6cd92518f2d62fff94f90e5a8ce7bb 1 parent ec6b2db
@anandology anandology authored
View
5 openlibrary/core/statsdb.py
@@ -40,6 +40,11 @@ def add_entry(key, data, timestamp=None):
else:
db.insert("stats", type='loan', key=key, created=t, updated=t, json=jsontext)
+def get_entry(key):
+ result = db.query("SELECT * FROM stats WHERE key=$key", vars=locals())
+ if result:
+ return result[0]
+
def update_entry(key, data, timestamp=None):
"""Updates an already existing entry in the stats table.
View
3  openlibrary/plugins/openlibrary/libraries.py
@@ -593,6 +593,9 @@ def on_loan_completed_statsdb(loan):
"t_end": t_end.isoformat(),
"status": "completed",
}
+ old = statsdb.get_entry(key)
+ if old:
+ d = dict(old, **d)
statsdb.update_entry(key, d)
def _get_loan_key(loan):
Please sign in to comment.
Something went wrong with that request. Please try again.