3liz / qgis-atlasprint

Export PDF using composer atlas feature, usable in server
13 stars 13 forks source link

QgsProject doesn't contain relations #36

Closed Gustry closed 4 years ago

Gustry commented 4 years ago

In the plugin, we have an issue with missing relation in QgsProject.

For example, I have an atlas on French department. And I have a relation to a French cities layer. In my atlas, I'm display a few cities in a table belonging to the current department.

In QGIS Desktop, it's working well, but using the atlasprint plugin, the relation table is empty.

    relations = project.relationManager()
    QgsMessageLog.logMessage('RELATIONS', 'atlasprint', Qgis.Info)
    for relation in relations.relations().keys():
        QgsMessageLog.logMessage(relation, 'atlasprint', Qgis.Info)
    QgsMessageLog.logMessage('FIN des relations', 'atlasprint', Qgis.Info)

Nothing in my logs. I added this code in the core.py for instance.

The problem is we have no access when the QgsProject is created, the object comes from executeRequest method in QgsService https://github.com/3liz/qgis-atlasprint/blob/master/atlasprint/service.py#L108 which is in QGIS core.

So it's maybe an upstream bug?

This is a regression from 1.2.4

CC @rldhont @dmarteau

Gustry commented 4 years ago

For a workaround with @rldhont , we removed the use of the relation in the atlas. We used a plain QGIS expression to filter my attribute table:

 "insee_dep" =  attribute(  @atlas_feature , 'insee_dep')

And it's working.

rldhont commented 4 years ago

Relations are read in the QGIS Project document after readProjectWithContext emission by QgsProject.

rldhont commented 4 years ago

@dmarteau can we made a test with py-qgis-server ?

Gustry commented 4 years ago

This has been fixed in QGIS 3.10.2 and master. QGIS 3.4 should be used with cautious about relation. I will add a note.