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

Fix fatal AttributeError using Arrow 0.14.5 #300

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
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
Fix fatal AttributeError using Arrow 0.14.5
Since Arrow 0.14.5, Arrow.replace() has dropped shift functionality
in favor of Arrow.shift(). This causes an AttributeError exception
every time watson is run.

The error message is: 'AttributeError: unknown attribute: "days"'
  • Loading branch information
davidag committed Aug 19, 2019
commit f5bfc62232607e06182262b67e0bb3cd502a3a5d
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Update zsh shell completion (#264).
- Fix fatal AttributeError using Arrow 0.14.5 (#300)

### Removed

Expand Down
11 changes: 5 additions & 6 deletions scripts/fuzzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@

now = arrow.now()

for date in arrow.Arrow.range('day', now.replace(months=-1), now):
for date in arrow.Arrow.range('day', now.shift(months=-1), now):
if date.weekday() in (5, 6):
# Weekend \o/
continue

start = date.replace(
hour=9, minute=random.randint(0, 59), seconds=random.randint(0, 59)
)
start = date.replace(hour=9, minute=random.randint(0, 59)) \
.shift(seconds=random.randint(0, 59))

while start.hour < random.randint(16, 19):
project, tags = random.choice(projects)
frame = watson.frames.add(
project,
start,
start.replace(seconds=random.randint(60, 4 * 60 * 60)),
start.shift(seconds=random.randint(60, 4 * 60 * 60)),
tags=random.sample(tags, random.randint(0, len(tags)))
)
start = frame.stop.replace(seconds=random.randint(0, 1 * 60 * 60))
start = frame.stop.shift(seconds=random.randint(0, 1 * 60 * 60))

watson.save()
6 changes: 3 additions & 3 deletions watson/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def status(watson, project, tags, elapsed):
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in report.")
@click.option('-f', '--from', 'from_', cls=MutuallyExclusiveOption, type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
mutually_exclusive=_SHORTCUT_OPTIONS,
help="The date from when the report should start. Defaults "
"to seven days ago.")
Expand Down Expand Up @@ -694,7 +694,7 @@ def _final_print(lines):
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in report.")
@click.option('-f', '--from', 'from_', cls=MutuallyExclusiveOption, type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
mutually_exclusive=_SHORTCUT_OPTIONS,
help="The date from when the report should start. Defaults "
"to seven days ago.")
Expand Down Expand Up @@ -835,7 +835,7 @@ def aggregate(ctx, watson, current, from_, to, projects, tags, output_format,
@click.option('-c/-C', '--current/--no-current', 'current', default=None,
help="(Don't) include currently running frame in output.")
@click.option('-f', '--from', 'from_', type=Date,
default=arrow.now().replace(days=-7),
default=arrow.now().shift(days=-7),
help="The date from when the log should start. Defaults "
"to seven days ago.")
@click.option('-t', '--to', type=Date, default=arrow.now(),
Expand Down
4 changes: 2 additions & 2 deletions watson/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_start_time_for_period(period):
if period == 'day':
start_time = arrow.Arrow(year, month, day)
elif period == 'week':
start_time = arrow.Arrow.fromdate(now.replace(days=-weekday).date())
start_time = arrow.Arrow.fromdate(now.shift(days=-weekday).date())
elif period == 'month':
start_time = arrow.Arrow(year, month, 1)
elif period == 'luna':
Expand Down Expand Up @@ -204,7 +204,7 @@ def apply_weekday_offset(start_time, week_start):
return start_time
now = datetime.datetime.now()
offset = weekdays[new_start] - 7 * (weekdays[new_start] > now.weekday())
return start_time.replace(days=offset)
return start_time.shift(days=offset)


def make_json_writer(func, *args, **kwargs):
Expand Down