Modify

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#8617 closed defect (invalid)

SVN post-commit hook fails

Reported by: fredrik@… Owned by: Russ Tyndall
Priority: normal Component: TimingAndEstimationPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.12

Description (last modified by Ryan J Ollos)

I tried to use the SVN post-commit hook, but was unable to make it work. When I enabled logging (commithook.log) I got the following error:

ERROR while processing: Unable to get database connection within 0 seconds. (TracError(<babel.support.LazyProxy object at 0x898175c>,))

Attachments (0)

Change History (13)

comment:1 Changed 13 years ago by Russ Tyndall

  • The error implies that you are having trouble connecting to the database.
  • Was there anything else in the log?
  • What does your svn post commit look like?
  • Can you (in a python shell) open the trac environment you are passing in the -p flag?

comment:2 Changed 13 years ago by Russ Tyndall

Meant to include this snippet above

import trac.env
e = trac.env.Environment('/path/to/your/trac') 

comment:3 Changed 13 years ago by fredrik@…

Replying to bobbysmith007:

  • The error implies that you are having trouble connecting to the database.
  • Was there anything else in the log?
  • What does your svn post commit look like?
  • Can you (in a python shell) open the trac environment you are passing in the -p flag?

1) The database works, I think?

2) No, nothing more in the log

3) I used the post-commit from TimingAndEstimationSVNPostCommitHook

3a) Using the simplified post-commit-script resulted in this in the logs:

[14:01:09] 2011-03-18 in svn post commit : <path/to/repo> : 1634 
[14:01:09] TracEnv:</path/to/trac/env> Repo:<path/to/repo> Rev:1634 Auth:fredrik

But nothing shows up in Trac.

4) Could execute the two commands in comment:2 without errors

comment:4 in reply to:  3 ; Changed 13 years ago by Russ Tyndall

  • I assume you adjusted all the paths appropriately?
  • Did the trac post commit log have anything interesting in its log (like more instances of

ERROR while processing: Unable to get database connection within 0 seconds. (TracError?(<babel.support.LazyProxy? object at 0x898175c>,)) )

  • Can you execute /usr/bin/python /var/trac/trac-post-commit.py -p "$TRAC_ENV" -r "$REV" -u "$AUTHOR" -m "$MESSAGE" 2>&1 (filling in the appropriate variables?) Does it work at all?
  • Are you sure that the user these end up running as all have appropriate permissions?
    • The place where that error would be the only one in the log, is on opening the environment. If the user executing the script didnt have permission tot eh filesystem in that location or something, I could imagine it manifesting in this way.

Just shooting in the dark at various troubles I have had in the past and how I debugged them.

comment:5 in reply to:  4 Changed 13 years ago by anonymous

  • Yes
  • Now I get the error ERROR while processing: 'NoneType' object has no attribute 'sync'
  • When I executed the script (tried as myself, root and wwwrun), I got no errors on screen, but exit status was 1.

comment:6 Changed 13 years ago by Russ Tyndall

The new error is different, but seems somewhat related (environment is failing to load correctly). Previously it seemed like connecting to the database was broken, but now it is connecting to the source control repo.

self.env = open_environment(project)
repos = self.env.get_repository()
repos.sync()
  • Do you correctly have the repository you are trying to post from, setup in trac? (You can see it in the browser)
    • Is it the "default" repository?
    • Do you have more than one repo?

This version of the script has only been tested against a single "default" repository. If you only have a single trac with a single repo, this post-commit should be fine.

The post commit I use is more complex, but does handle multiple repositories. I have not included it because it contains code specific to my environment that is somewhat difficult to disentangle (about building links to gitweb for non trac git repositories and handling differences between git and svn repositories across our various trac instances). I can post that if you think that might meet your needs better, but it will definitely be a more complex setup and will require digging through the code to get it behaving exactly as you desire.

comment:7 Changed 13 years ago by fredrik@…

I do know it is not the "default" repository, but it is the only one present.

comment:8 Changed 13 years ago by Russ Tyndall

Not sure about the "default", as it seems unnecessary to specify that if there is only one. This is a working repository configuration for me.

[trac]
repository_dir = /var/svn/test-svn
repository_type = svn

With it I can execute the following in python shell and get a repository object back.

import trac.env
e = trac.env.Environment('/var/trac/test-svn/')
e.get_repository()

This is what the post commit is complaining about. Can you execute it and get a repository object?

Sorry this has been such a pain to get working. I am sure we will get it eventually though,

Russ

comment:9 Changed 13 years ago by Ryan J Ollos

Description: modified (diff)

comment:10 Changed 13 years ago by fredrik@…

No errors when I run those commands as wwwrun or root. So it seems something different happens when running the python-script.

I thank you for being patient and helpful.

comment:11 Changed 13 years ago by Russ Tyndall

There is only one reference to sync, so the error 'NoneType' object has no attribute 'sync' must come from that one location, which makes it seem very much like that the error is opening the environment.

Perhaps try adding these log messages near where the error messages are occuring, as they might shed light on why this is being problematic.

class CommitHook:
    def __init__(self, project=options.project, author=options.user,
                 rev=options.rev, url=options.url):
        log ("About to Open Project: %s", project)

        self.env = open_environment(project)
        repos = self.env.get_repository()

        log ("Got ENV : %s - Repo: %s", self.env, repos)

        repos.sync()
        ...

Sorry this was supposed to be posted last friday :(

comment:12 Changed 13 years ago by fredrik@…

Resolution: invalid
Status: newclosed

Found the problem after adding those log messages: triple checked my trac.ini, and found out that repository_dir was empty.

Does repository information get stored in different places, since everything else worked before?

comment:13 Changed 13 years ago by Russ Tyndall

Trac 12 changed how repositories are setup, allowing multiple repos for a single trac instance. The repository_dir key is no longer the only way to configure a repository in trac, but that had previously been "the way" that this was configured.

My guess is that repository configuration dir can also be set as follows and have everything in trac work (other than possibly this post commit (not sure havent tried this alternative config with this post commit)). Perhaps this is how the trac installer installs this by default now; I'm not sure because I use a very custom install process.

[repositories]
.alias = design # set design to be default
design.dir = /var/svn/Design
design.url = https://svn.acceleration.net/svn/Design

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Russ Tyndall.
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.