#5190 - Add metadata_modified field to resource#5236
Conversation
|
@amercader regarding new unit tests, I'm thinking on what's the best way to do testing of this. In our codebase we have several ways to do it for the field in package:
today = datetime.date.today().strftime("%Y-%m-%d")
assert result["metadata_modified"].startswith(today)
def replace_datetime(dict_, key):
assert key in dict_
dict_[key] = u"2019-05-24T15:52:30.123456"
replace_datetime(dataset2, "metadata_modified")
assert abs((now - dt).total_seconds()) < 10@smotornyuk proposed in a PR (can't find it) to use freezegun but it mocks Creating a new mock is not that trivial, since Python built-in types are immutable. I tried to create a fixture like the following one proposed here: import datetime
import pytest
FAKE_TIME = datetime.datetime(2020, 12, 25, 17, 5, 55)
@pytest.fixture
def patch_datetime_utcnow(monkeypatch):
class mydatetime:
@classmethod
def utcnow(cls):
return FAKE_TIME
monkeypatch.setattr(datetime, 'datetime', mydatetime)
def test_patch_datetime(patch_datetime_now):
assert datetime.datetime.now() == FAKE_TIMEBut it throws errors on other tests and codebase because we are mocking the I can keep testing as we are doing now, but I thought that it was good to raise this and found a holistic approach for how we test this time based logic. |
|
@amercader discard the last comment, writing it just make me read more carefully the docs and issues and seems that
Sorry, holidays are coming soon :) I will add some tests using |
|
If we add these fields then we can stop updating the |
| Column('size', types.BigInteger), | ||
| Column('created', types.DateTime, default=datetime.datetime.utcnow), | ||
| Column('last_modified', types.DateTime), | ||
| Column('metadata_modified', types.DateTime), |
There was a problem hiding this comment.
The behaviour for metadata_modified at the package level is to have utcnow as default, which I think it makes sense if you are using this field to track changes in a resource
There was a problem hiding this comment.
Ah, I see now that the field will be set to utcnow as the value of the field will be different, but I'd add it here anyway for consistency
| obj.url_changed = True | ||
| if key == 'url' and not new and obj.url != value: | ||
| obj.url_changed = True | ||
| if getattr(obj, key) != value: |
There was a problem hiding this comment.
If the key was not present in the resource before this will raise an AttributeError.
There was a problem hiding this comment.
Sorry ignore me, I was reading the code wrong
|
@pdelboca I went ahead and added the missing bits to this before merging. More important ones:
|
|
@wardi this PR only included the addition of the |
Fixes #5190
Proposed fixes:
This PR adds a metadata_modified field to the Resource model to keep track of changes. It is updated in
resource_dict_save(model_save.py) only if new values being saved differs from the actual ones.Features:
Please [X] all the boxes above that apply