question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValueError: microsecond must be in 0..999999

See original GitHub issue

Hello, all

I’ve got a new error after the v2.0.0 milestone, likely relating to #172. Here’s the error text:

  File "/Users/space/Documents/Programming/dt-blog-platform/api-server/db/objs.py", line 268, in commit
    self.updatedon = datetime.datetime.utcnow()
  File "/var/root/.local/share/virtualenvs/api-server-DI-zCP9m/lib/python3.6/site-packages/umongo/document.py", line 295, in __setattr__
    self._data.set(name, value, to_raise=AttributeError)
  File "/var/root/.local/share/virtualenvs/api-server-DI-zCP9m/lib/python3.6/site-packages/umongo/data_proxy.py", line 152, in set
    value = field._deserialize(value, name, None)
  File "/var/root/.local/share/virtualenvs/api-server-DI-zCP9m/lib/python3.6/site-packages/umongo/fields.py", line 245, in _deserialize
    return ret.replace(microsecond=round(ret.microsecond, -3))
ValueError: microsecond must be in 0..999999

My guess is something funky is going on either with my system, or maybe the round isn’t working properly? Not too sure, but this should be a simple one.

The way I did this is set a StrictDateTimeField equal to datetime.datetime.utcnow() in an overriden commit method. Ex:

@instance.register
class Foo(Document):
    name = fields.StringField()
    updatedon = fields.StrictDateTimeField()

    def commit(self, *args, **kwargs):
        self.updatedon = datetime.datetime.utcnow()
        return super(Foo, self).commit(*args, **kwargs)

This error happens when calling the commit method on the object.

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
enugentdtcommented, Apr 8, 2019

Can do. I’ll have a report for you tomorrow morning EDT

Thanks, Eamonn

Sent from my iPhone

On Apr 7, 2019, at 6:36 PM, Jérôme Lafréchoux notifications@github.com wrote:

Thanks for reporting.

This is due to millisecond being rounded to 1000000. In this case, second should be incremented and millisecond set to 0.

This is my mistake. It already happened to me in another context and I forget about it when submitting #172. Sorry about that.

I submitted #190 to fix this. @enugentdt, do you think you could check if it solves your problem?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

0reactions
lafrechcommented, Apr 8, 2019

I prefer to rely on comprehensive testing rather than release into the wild until someone complains about a broken app. But frankly, I’m confident about the patch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: ValueError: microsecond must be in 0..999999 while ...
I'm currently trying calculate the leadtime of all outlook messages within a specific outlook folder using python. In general the script ...
Read more >
How do I fix ValueError: microsecond must be in 0..999999?
A microsecond field value must be in the range . A negative value or a value greater than or equal to one million...
Read more >
fix bug: microsecond must be in 0..999999 #1655 - GitHub
I used pywin32 to access outlook and sometimes exception thrown by pywin32. It is critical value problem, so I just set milliseconds to...
Read more >
str(datetime_obj) doesn't include microseconds if their value is 0
This behavior is intentional and is documented in the datetime.isoformat() docs: """ Return a string representing the date and time in ISO 8601...
Read more >
pypyodbc - issue #36 - Google Code
TIMESTAMP columns in SAP HANA cause ValueError: microsecond must be in 0.999999. Posted on Feb 25, 2014 by Swift Elephant.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found