Modify

Opened 10 years ago

Closed 10 years ago

#12156 closed defect (fixed)

object of type 'datetime.datetime' has no len()

Reported by: dhealey@… Owned by: Ryan J Ollos
Priority: normal Component: TicketValidatorPlugin
Severity: normal Keywords: time date
Cc: Trac Release: 1.0

Description (last modified by Ryan J Ollos)

Oops… Trac detected an internal error:

TypeError: object of type 'datetime.datetime' has no len()

This is probably a local installation issue. You should a ticket at the admin Trac to report the issue. Found a bug in Trac?

If you think this should work and you can reproduce the problem, you should consider creating a bug report.

Note that the TicketValidator plugin seems to be involved. Please report this issue to the plugin maintainer.

Before you do that, though, please first try searching for similar issues, as it is quite likely that this problem has been reported before. For questions about installation and configuration of Trac or its plugins, please try the mailing list instead of creating a ticket.

Otherwise, please a new bug report describing the problem and explain how to reproduce it.

Python Traceback Most recent call last:

File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 551, in _dispatch_request
  dispatcher.dispatch(req)
File "build/bdist.linux-x86_64/egg/trac/web/main.py", line 225, in dispatch
  resp = chosen_handler.process_request(req)
File "build/bdist.linux-x86_64/egg/trac/ticket/web_ui.py", line 175, in process_request
  return self._process_ticket_request(req)
File "build/bdist.linux-x86_64/egg/trac/ticket/web_ui.py", line 656, in _process_ticket_request
  valid = self._validate_ticket(req, ticket, not valid) and valid
File "build/bdist.linux-x86_64/egg/trac/ticket/web_ui.py", line 1363, in _validate_ticket
  for field, message in manipulator.validate_ticket(req, ticket):
File "build/bdist.linux-x86_64/egg/ticketvalidator/core.py", line 48, in validate_ticket
  if self._is_empty(ticket[field_name])]
File "build/bdist.linux-x86_64/egg/ticketvalidator/core.py", line 28, in _is_empty
  if len(value) == 0:

Attachments (0)

Change History (15)

comment:1 Changed 10 years ago by Ryan J Ollos

Description: modified (diff)

comment:2 Changed 10 years ago by Ryan J Ollos

Are you really running Trac 1.0? Or are you perhaps running 1.1.x?

What is the content of your [ticketvalidator] section in trac.ini?

comment:3 Changed 10 years ago by anonymous

I am running Trac 1.1.3dev.

After looking through your code and my environment, it appears that there is an interesting issue with regard to the date/time formatting. In lue of an actual fix for the issue : Code of issue :

class RequiredFieldValidator(Component):
    """Basic ticket validator for required fields"""

    implements(ITicketManipulator)

    def _is_empty(self, value):
        """Check if 'value' is empty.

        :param value: the value to check
        :type value: object"""

        if value is None:
            return True

        if len(value) == 0:
            return True

        return False

Change I made in order to allow the date/time format currently being used :

class RequiredFieldValidator(Component):
    """Basic ticket validator for required fields"""

    implements(ITicketManipulator)

    def _is_empty(self, value):
        """Check if 'value' is empty.

        :param value: the value to check
        :type value: object"""

        if value is None:
            return True

#        if len(value) == 0:
#            return True

        return False

Once commented out, there are no additional issues whatsoever, I've spent the better part of the night testing, and found no instance in which it was an issue.

Last edited 10 years ago by Ryan J Ollos (previous) (diff)

comment:4 Changed 10 years ago by dhealey@…

Sorry the above comment was from Me, David Healey dhealey@…

comment:5 Changed 10 years ago by Ryan J Ollos

Owner: changed from Max Stewart to Ryan J Ollos
Priority: highestnormal
Severity: criticalnormal
Status: newaccepted

comment:6 Changed 10 years ago by Ryan J Ollos

In 14383:

Remove the "unpythonic" method _is_empty from the RequiredFieldValidator class (untested). Refs #12156.

comment:7 Changed 10 years ago by Ryan J Ollos

Could you please check if [14383] fixes the issue for you?

comment:8 Changed 10 years ago by dhealey@…

By removing the method, it appears to work correctly, however does not actually function as expected. It does no validation and allows for null required fields which is not the intended action. removing the len(value) however allows for validation with both plan text and date/time formatted input, which I think is the actual problem, since len(value) expects an integer, it doesn't see the date/time as anything but a "0" so returns true.

comment:9 Changed 10 years ago by dhealey@…

Personally speaking, I'd love this function to be a part of the core Trac ticketing system, however, it doesn't appear that it will ever be, which I think, is to there detriment. There should be "required" input give the status of a particular ticket.

comment:10 Changed 10 years ago by Ryan J Ollos

I'll do some more testing and post another revision later today.

comment:11 Changed 10 years ago by dhealey@…

Thank you. I appreciate the assistance.

comment:12 Changed 10 years ago by dhealey@…

After extensive testing, your changes work very well. date/time validation and/or select field input combination works really great. I've changed the template interface a bit locally, and will post the changes here, it just looks better and is more easily understood with what I've changed. feel free to use them if you'd like. And again, thank you very much for your assistance.

Original Template Code :

<legend>Rules</legend>
                
                <p class="hint">
                State is the 'status' of the ticket when the specified 
                fields are required.  Fields is a comma separated list 
                of required ticket properties.
                </p>
                
                <table>
                    <thead>
                        <tr>
                            <th>State</th>
                            <th>Fields</th>

Modified Template code :

<legend>Validator Rules</legend>

                                <p class="hint">
                                <b>Status Change To</b> -- Is the 'status' of the ticket when the specified
                                ticket properties, field(s) are to be required.</p>

                                <p class="hint">
                                <b>Field(s) Required</b> -- Can be a comma separated list
                                of required ticket properties, field(s) or a single ticket property or field
                                requirement.
                                </p>

                                <table>
                                        <thead>
                                                <tr>
                                                        <th><u>Status Changes to</u></th>
                                                        <th><u>Field(s) Required</u></th>
Last edited 10 years ago by Ryan J Ollos (previous) (diff)

comment:13 Changed 10 years ago by Ryan J Ollos

Thanks, I'll look into your template changes. Do you know if #12121 is fixed now as well?

For future reference in creating patches, please see trac:TracDev/SubmittingPatches.

comment:14 Changed 10 years ago by Ryan J Ollos

In 14386:

0.2dev: Improved appearance of Validation Rules admin page. Refs #12156.

Based on a patch by dhealey@...

comment:15 Changed 10 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.