Skip to content

Commit

Permalink
Fix server product list mismatch in multi server
Browse files Browse the repository at this point in the history
If the product doesn't find in the cache, try to get it from the
database.
  • Loading branch information
csordasmarton committed Mar 21, 2018
1 parent 1b518e9 commit 54094b6
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion libcodechecker/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,35 @@ def get_product(self, endpoint):
"""
Get the product connection object for the given endpoint, or None.
"""
return self.__products.get(endpoint, None)
if endpoint in self.__products:
return self.__products.get(endpoint)

LOG.debug("Product with the given endpoint '%s' does not exist in "
"the local cache. Try to get it from the database.",
endpoint)

# If the product doesn't find in the cache, try to get it from the
# database.
try:
cfg_sess = self.config_session()
product = cfg_sess.query(ORMProduct) \
.filter(ORMProduct.endpoint == endpoint) \
.limit(1).one_or_none()

if not product:
return None

self.add_product(product)
permissions.initialise_defaults('PRODUCT', {
'config_db_session': cfg_sess,
'productID': product.id
})

return self.__products.get(endpoint, None)
finally:
if cfg_sess:
cfg_sess.close()
cfg_sess.commit()

def get_only_product(self):
"""
Expand Down

0 comments on commit 54094b6

Please sign in to comment.