Hi, @dsuch! Thanks for the change. I am afraid something is not working fine, though. I am getting the following error on the logs:
2018-11-11 08:42:57,491 - ERROR - 230:DummyThread-22 - zato.broker:57 - Could not handle broker msg:`Bunch(action='106420', cache_name='logins', expires_at=0.0, expiry=0.0, key='id-1', msg_type='0002', source_worker_id='1.1.136.5da98b49698360508416a62b', value={'username': 'jsabater', 'surname': 'Sabater', 'name': 'Jaume', 'id': 1, 'is_admin': True, 'email': 'jsabater@gmail.com'})`, e:`Traceback (most recent call last):
File "/opt/zato/3.0/code/zato-broker/src/zato/broker/__init__.py", line 52, in on_broker_msg
getattr(self, handler)(msg)
File "/opt/zato/3.0/code/zato-server/src/zato/server/base/worker/cache_builtin.py", line 46, in on_broker_msg_CACHE_BUILTIN_STATE_CHANGED_SET
self.cache_api.sync_after_set(_BUILTIN, msg)
File "/opt/zato/3.0/code/zato-server/src/zato/server/connection/cache.py", line 863, in sync_after_set
self.caches[cache_type][data.cache_name].sync_after_set(data)
File "/opt/zato/3.0/code/zato-server/src/zato/server/connection/cache.py", line 542, in sync_after_set
self.impl.set(data.key, data.value, data.expiry, None)
File "src/zato/cy/cache.pyx", line 624, in src.zato.cy.cache.Cache.set
TypeError: set() takes exactly 5 positional arguments (4 given)
This is the current code being executed:
class Get(Service):
"""Service class to get a login by id."""
"""Channel /genesisng/logins/{id}/get."""
class SimpleIO:
input_required = (Integer('id'))
# Passwords never travel back to the client side
output_optional = ('id', 'username', 'name', 'surname', 'email',
'is_admin')
skip_empty_keys = True
def handle(self):
conn = self.user_config.genesisng.database.connection
cache_control = self.user_config.genesisng.cache.default_cache_control
id_ = self.request.input.id
# Check whether a copy exists in the cache
cache_key = 'id-%s' % id_
cache = self.cache.get_cache('builtin', 'logins')
cache_data = cache.get(cache_key, details=True)
if cache_data:
self.response.status_code = OK
self.response.headers['Cache-Control'] = cache_control
self.response.headers['Last-Modified'] = format_date_time(
cache_data.last_write)
self.response.headers['ETag'] = md5(str(
cache_data.value)).hexdigest()
self.response.payload = cache_data.value
return
with closing(self.outgoing.sql.get(conn).session()) as session:
result = session.query(Login).filter(Login.id == id_).one_or_none()
if result:
# Save the record in the cache, minus the password
result = result.asdict()
del (result['password'])
cache_data = cache.set(cache_key, result, details=True)
# TODO: Check for cache_data or return result, not value
# Return the result
self.response.status_code = OK
self.response.headers['Cache-Control'] = cache_control
self.response.headers['Last-Modified'] = format_date_time(
cache_data.last_write)
self.response.headers['ETag'] = md5(str(
cache_data.value)).hexdigest()
self.response.payload = cache_data.value
else:
self.response.status_code = NOT_FOUND
self.response.headers['Cache-Control'] = 'no-cache'
There is something weird with the Last-Modified heders, as the datetimes differ too much:
$ curl -v -g "http://127.0.0.1:11223/genesisng/logins/1/get"; echo ""
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 11223 (#0)
> GET /genesisng/logins/1/get HTTP/1.1
> Host: 127.0.0.1:11223
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Zato
< Date: Sun, 11 Nov 2018 08:43:22 GMT
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: application/json
< ETag: ca38b9699e2ebad80e2dd98a1b287018
< X-Zato-CID: cd8d2a817c5038b3688e695b
< Cache-Control: public,max-age=300
< Last-Modified: Sun, 11 Nov 2018 08:43:11 GMT
<
* Closing connection 0
{"response": {"username": "jsabater", "surname": "Sabater", "name": "Jaume", "id": 1, "is_admin": true, "email": "jsabater@gmail.com"}}
$ curl -v -g "http://127.0.0.1:11223/genesisng/logins/1/get"; echo ""
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 11223 (#0)
> GET /genesisng/logins/1/get HTTP/1.1
> Host: 127.0.0.1:11223
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Zato
< Date: Sun, 11 Nov 2018 08:43:23 GMT
< Connection: close
< Transfer-Encoding: chunked
< Content-Type: application/json
< ETag: ca38b9699e2ebad80e2dd98a1b287018
< X-Zato-CID: 2bf6eb3d6d2cbd459fed843d
< Cache-Control: public,max-age=300
< Last-Modified: Sun, 11 Nov 2018 08:42:57 GMT
<
* Closing connection 0
{"response": {"username": "jsabater", "surname": "Sabater", "name": "Jaume", "id": 1, "is_admin": true, "email": "jsabater@gmail.com"}}
This code, unless I’m missing something, was working fine, Last-Modified headers-wise, before I was using details=True when setting the cache entry.
Or maybe installation of Zato updates was not performed correctly. I deleted all entries in the cache through the web-admin panel, but didn’t delete the cache itself (the collection).