Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure dataset_lifetime bind is defined for DBS3Buffer/NewSubscription #11179

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/python/WMComponent/DBS3Buffer/MySQL/NewSubscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def _createPhEDExSubBinds(self, datasetID, subscriptionInfo, custodialFlag):

# DeleteFromSource is not supported for move subscriptions
delete_blocks = None
# if None, force it to 0 as per the table schema
dataLifetime = subscriptionInfo.get('DatasetLifetime', 0) or 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is quite ambiguous, I think. The .get() method is returning a proper default value, but we'd better have an explicit check for None value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@todor-ivanov you can see for your self:

# if you don't provide default value the type is None
>>> d={}
>>> d.get("foo")
>>> r=d.get("foo")
>>> type(r)
<class 'NoneType'>

# while if you provide default value the type is type of that value
>>> r=d.get("foo", 0)
>>> type(r)
<class 'int'>

Therefore, the line is correct, i.e. it is always return integer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vkuznet
I do see what the line is doing. I did not mean it is wrong. I simply wanted to say: The reader may just miss the fact that there is also another possibility the value to be None at first place - provided as such value from the dictionary itself. But as written here also works perfectly fine. Lets not waste time on such minor things. Forget about my comment @amaltaro. The code is good.

if custodialFlag:
sites = subscriptionInfo['CustodialSites']
phedex_group = subscriptionInfo['CustodialGroup']
Expand All @@ -59,9 +61,8 @@ def _createPhEDExSubBinds(self, datasetID, subscriptionInfo, custodialFlag):
'move': isMove,
'priority': subscriptionInfo['Priority'],
'phedex_group': phedex_group,
'delete_blocks': delete_blocks}
if subscriptionInfo['DatasetLifetime'] is not None:
bind.update(dict(dataset_lifetime=subscriptionInfo['DatasetLifetime']))
'delete_blocks': delete_blocks,
'dataset_lifetime': dataLifetime}
binds.append(bind)
return binds

Expand Down