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

inconsistency between date and datetime objects #24

Closed
sannant opened this issue Jan 24, 2021 · 6 comments
Closed

inconsistency between date and datetime objects #24

sannant opened this issue Jan 24, 2021 · 6 comments

Comments

@sannant
Copy link

sannant commented Jan 24, 2021

Using dtool create, I had the error that datetime.date has no attribute date.

The bug is caused by the following lines:

elif isinstance(value, datetime.date):
def parse_date(value):
try:
date = datetime.datetime.strptime(value, "%Y-%m-%d")
except ValueError as e:
raise click.BadParameter(
"Could not parse date, {}".format(e), param=value)
return date
new_value = click.prompt(key, default=value, value_proc=parse_date)
d[key] = new_value.date().isoformat()

The default happens to be a date object, not a datetime object, but the parse_date function returns a datetime object.

Here is the proposed fix:

        elif isinstance(value, datetime.date):
            def parse_date(value):
                try:
                    date = datetime.datetime.strptime(value, "%Y-%m-%d")
                except ValueError as e:
                    raise click.BadParameter(
                        "Could not parse date, {}".format(e), param=value)
                return date.date()
            new_value = click.prompt(key, default=value, value_proc=parse_date)
            d[key] = new_value.isoformat()

This might be related to #22, since something has been changed from datetime to date.

I wonder why this error comes up now, since the code dates from may.

Current python version is 3.8.

@tjelvar-olsson
Copy link
Contributor

Hi Antoine,

Could you send me the exact command you ran and the full error that you got?
Could you also please send me the output of running dtool --version on your system?

This will help me try to work out what is going on.

Best,
Tjelvar

@sannant
Copy link
Author

sannant commented Jan 25, 2021

Hi Tjelvar,

here the dtool readme template:

---
creation_date: {date}

here the command that failed, after a successfull dtool create test

dtool readme interactive test
creation_date [2021-01-25]: 
Traceback (most recent call last):
  File "/usr/local/bin/dtool", line 8, in <module>
    sys.exit(dtool())
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/dtool_create/dataset.py", line 259, in interactive
    descriptive_metadata = _prompt_for_values(descriptive_metadata)
  File "/usr/local/lib/python3.8/site-packages/dtool_create/dataset.py", line 98, in _prompt_for_values
    d[key] = new_value.date().isoformat()
AttributeError: 'datetime.date' object has no attribute 'date'
dtool --version
dtool, version 

Base:
dtoolcore, version 3.18.0
dtool-cli, version 0.7.0

Storage brokers:
file, dtoolcore, version 3.18.0
symlink, dtool-symlink, version 0.3.0
smb, dtool-smb, version 0.1.0
s3, dtool-s3, version 0.10.0
https, dtool-http, version 0.5.0
http, dtool-http, version 0.5.0
ecs, dtool-ecs, version 0.5.0

Plugins:
dtool-config, version 0.4.0
dtool-create, version 0.23.1
dtool-info, version 0.16.1

Thank you for the help,

Best,

Antoine Sanner

@tjelvar-olsson
Copy link
Contributor

Thanks, I've managed to reproduce the issue. Will look into what is causing it now.

@tjelvar-olsson
Copy link
Contributor

Fixed in b4d9ef7

@sannant
Copy link
Author

sannant commented Jan 27, 2021

Works ! Thank you !

@tjelvar-olsson
Copy link
Contributor

Fix now in latest release of dtool-create: https://pypi.org/project/dtool-create/0.23.2/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants