Skip to content

Conversation

pandafy
Copy link
Member

@pandafy pandafy commented Sep 9, 2025

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #634

Blockers

@pandafy pandafy marked this pull request as ready for review September 21, 2025 11:48
def get_reset_timestamps(self):
try:
return resets[self.reset](self.user)
return resets[self.reset](self.user, self)
Copy link
Member Author

Choose a reason for hiding this comment

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

Passing the counter object to the reset allows flexibility to perform operation on user, group and group_check objects.

@pandafy
Copy link
Member Author

pandafy commented Sep 22, 2025

@nemesifier can you suggest me how can I incorporate this implementation detail in https://openwisp.io/docs/dev/radius/user/enforcing_limits.html?

@pandafy pandafy force-pushed the issues/634-counters-return-multiple-values branch 2 times, most recently from ab40470 to 2ddafa9 Compare September 23, 2025 11:10
@pandafy pandafy self-assigned this Sep 24, 2025
# BACKWARD COMPATIBILITY: In previous versions of openwisp-radius,
# the Counter.reply_name was a string instead of a tuple. Thus,
# we need to convert it to a tuple if it's a string.
if not hasattr(self, "reply_name"):
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK, getattr and hasattr have the same computing cost, so it's better to use getattr if we need to use the result later.

Suggested change
if not hasattr(self, "reply_name"):
reply_name = getattr(self, "reply_name", None)
if not reply_name:

raise NotImplementedError(
"Counter classes must define 'reply_names' property."
)
if isinstance(self.reply_name, str):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if isinstance(self.reply_name, str):
if isinstance(reply_name, str):

"Counter classes must define 'reply_names' property."
)
if isinstance(self.reply_name, str):
return (self.reply_name,)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return (self.reply_name,)
return (reply_name,)

)
if isinstance(self.reply_name, str):
return (self.reply_name,)
return self.reply_name
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return self.reply_name
return reply_name

@pandafy pandafy force-pushed the issues/634-counters-return-multiple-values branch from 2ddafa9 to b27a5b7 Compare September 29, 2025 15:16
Base automatically changed from issues/643-coa to master September 29, 2025 15:45
Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

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

There's a conflict, please update this PR.

@pandafy pandafy force-pushed the issues/634-counters-return-multiple-values branch from b27a5b7 to d142269 Compare September 30, 2025 09:06
@coveralls
Copy link

coveralls commented Sep 30, 2025

Coverage Status

coverage: 98.717% (+0.004%) from 98.713%
when pulling 13c223a on issues/634-counters-return-multiple-values
into 340a64e on master.

@nemesifier nemesifier moved this from Backlog to In progress in 25.09 Release Sep 30, 2025
Comment on lines 11 to 12
# TODO: Remove before merging
- issues/643-coa
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# TODO: Remove before merging
- issues/643-coa

Comment on lines 308 to 309
if consumed > int(obj.value):
consumed = int(obj.value)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if consumed > int(obj.value):
consumed = int(obj.value)
value = int(obj.value)
if consumed > value:
consumed = value

return row[0] or 0

def check(self, gigawords=gigawords):
def check(self, gigawords=True):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def check(self, gigawords=True):
def check(self):



def _daily(user=None):
def _daily(user=None, counter=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _daily(user=None, counter=None):
def _daily(user=None, **kwargs):



def _weekly(user=None):
def _weekly(user=None, counter=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _weekly(user=None, counter=None):
def _weekly(user=None, **kwargs):



def _monthly(user=None):
def _monthly(user=None, counter=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _monthly(user=None, counter=None):
def _monthly(user=None, **kwargs):

return _timestamp(start, end)


def _monthly_subscription(user):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _monthly_subscription(user, **kwargs):



def _never(user=None):
def _never(user=None, counter=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def _never(user=None, counter=None):
def _never(user=None, **kwargs):

@pandafy pandafy force-pushed the issues/634-counters-return-multiple-values branch from e53b0a4 to 13c223a Compare September 30, 2025 18:35
@nemesifier nemesifier added the enhancement New feature or request label Sep 30, 2025
@nemesifier nemesifier merged commit 790d2e8 into master Sep 30, 2025
17 checks passed
@nemesifier nemesifier deleted the issues/634-counters-return-multiple-values branch September 30, 2025 20:58
@github-project-automation github-project-automation bot moved this from In progress to Done in 25.09 Release Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

[change] Allow counters to return multiple replies
3 participants