Image copyrightAFPImage caption
President Putin hit Turkey with a raft of sanctions after a Russian attack jet was shot down in the Turkey-Syria border area

Turkey has seen an upheaval in its foreign and domestic politics, exacerbated by the near-disastrous coup attempt on 15 July.

In view of the current "frost" in the AKP government's relations with both the US and the EU, President Recep Tayyip Erdogan's decision to choose Russia for his first official visit abroad since the botched coup appears rich in symbolism.

And Western leaders will be looking on nervously.

The EU's migrant deal with Turkey has run into trouble and the US is under pressure to extradite self-exiled Islamic leader Fethullah Gulen, whom Turkey blames for the coup.

But Tuesday's visit is not a snap decision by the Turkish state in reaction to a perceived lack of visible and credible Western support in times of crisis, nor is it in appreciation of President Putin's swift support.

The history goes farther back than that.

More on this story:

Some years ago Ahmet Davutoglu, Turkey's then foreign minister and later prime minister, coined the slogan "Zero problems with all neighbours" as Turkey adapted its policy to meet the wave of changes during the so-called Arab Spring.

By the end of last year, the Turkish leadership had problems with all its neighbours and partners and a diminishing crowd of friends, because of negative developments in Syria and Iraq as well as failures in Turkish policy.

And as Turkey's security interests have worsened in Syria, with Kurdish militants either side of the border, it has clearly become a strategic necessity for Ankara to bow to realities and look for opportunities for an honourable retreat.

This applies in particular to the Turkish government´s policy towards Russia.

Image copyrightReutersImage caption
In November Turkey shot down a Russian warplane in a mountainous area of northern Syria

Earlier relations were based essentially and pragmatically on a number of points of economic interdependence.

Turkey needed Russian petroleum deliveries, access to nuclear and other elements of technology. It also relied on access to the Russian market and a continued flow of Russian tourists.

Both also had a joint interest in basic stability in the Black Sea area, in view of the 1936 Montreux Declaration on access to the Bosphorus and Dardanelles straits.

But the downing of the Russian SU-24 fighter jet on 24 November 2015 dramatically raised Turkish-Russian tensions within weeks of Russia's military intervention backing up President Bashar al-Assad in Syria.

Syria's leader has become President Erdogan's sworn enemy of late. and Mr Putin's ensuing punitive actions have hurt Turkey economically and politically.

Resetting relations

It came as no surprise when Turkey signalled a change in policy in mid-May.

Out went Prime Minister Ahmet Davutoglu and in came Binali Yildirim, who soon announced that the time had come for Turkey to "decrease the number of enemies and increase the number of friends", clearly alluding to Russia and Israel for starters.

Since then President Erdogan has issued some kind of rare "apology", deemed politically sufficient by team Putin - although Russian Foreign Minister Sergei Lavrov has insisted that sustainable normalisation will depend on how the two countries co-operate in the quagmire of the Syria crisis.

Mr Erdogan takes to St Petersburg a very broad agenda and a huge delegation. The two states are expected to reset the Turkish Stream gas pipeline project, as well as cover nuclear power plant construction and perhaps other energy related items.

Media playback is unsupported on your device

Media captionSunday's rally in Istanbul was an unprecedented show of support for President Erdogan, as BBC's Bethany Bell reports

They will also include resuming tourism, food exports and construction, which have all been hit hard since Russia imposed sanctions in November.

Presumably some efforts will also be made to clear the way for some understanding on Syria.

But the symbolic nature of this visit within weeks of the botched coup is far from lost on those in the US and EU who are searching for signs of possible permanent policy change.

Turkey is after all a key Nato power. And it has new sensitivities since the traumatic events of 15 July, while the West has been uneasy at President Erdogan's heavy-handedness before and especially since the attempted coup.

To the delight of President Putin, Mr Erdogan is presumably happy to keep the West wondering, and sweating, for now.