Comment 16 for bug 1266962

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Related fix merged to oslo-incubator (master)

Reviewed: https://review.openstack.org/67484
Committed: https://git.openstack.org/cgit/openstack/oslo-incubator/commit/?id=70ebb197a112bbc832bf8528b69dcfc164288539
Submitter: Jenkins
Branch: master

commit 70ebb197a112bbc832bf8528b69dcfc164288539
Author: Roman Podoliaka <email address hidden>
Date: Fri Jan 17 16:26:24 2014 +0200

    Fix mocking of utcnow() for model datetime cols

    Now when we are going to deprecate timeutils.set_time_override()
    and use mock instead, it easy to hit the following gotcha: when
    testr does tests discovering, it imports all modules within a given
    directory and it might happen that common.db.sqlalchemy.models
    is imported before timeutils.utcnow() is mocked in a test case.
    In this case the SQLAlchemy model will save the reference to the
    original timeutils.utcnow() function, which will be called later
    when the model will be saved to a DB, if created_at or updated_at
    value aren't provided.

    In order to overcome this we can defer resolution of timeutils.utcnow
    reference by passing lambda functions to SA Column __init__().

    Related-Bug: #1266962

    Change-Id: I7adce90eacb4a3f334d77da7b4a176c31ff818ed